Smarthome: Move groovy unit tests to JUnit, mockito & hamcrest

Created on 25 Apr 2017  ·  13Comments  ·  Source: eclipse-archived/smarthome

In addition to the move to Java 8 with #2926 we want to move the existing groovy unit tests to a pure Java setup with JUnit, mockito and hamcrest. By getting rid of groovy we want to streamline the tooling and reduce complexity.

Steps to take:

  • introduce OSGi dependencies for mockito & hamcrest -> will be introduced by #3258.
  • adopt the archetype creating the binding test fragment to provide a mockito/hamcrest template test.
  • adopt the documentation for binding tests here.
  • refactor existing groovy tests to use the new test infrastructure.
help wanted

Most helpful comment

When the open Groovy to Java migration PRs are merged @maggu2810 , the remaining Groovy file and bundle counts should be 0. :smile:

After that I think we could do a final cleanup of documentation, infra (e.g. OSGiTest) and other leftovers to get this issue closed.

All 13 comments

@maggu2810 I assume that plan gets your approval?

Sure :wink: :+1:

In addition to the move to Java 8 with #2926 we want to move the existing groovy unit tests to a pure Java setup with JUnit, mockito and hamcrest.

This is great! Some of these tests actually doesn't require an OSGi runtime anymore, but Tycho Surefire plugin still launches one for them. Eclipse test plugins can be executed by the Maven Surefire plugin as pure unit tests.

Just an update on this:

➜  find . -name "*.groovy" | grep "/src/" | wc -l                                                                                                                                                               
     100

Exactly 100 left 😄

Still some work left.

$ find . -name "*.groovy" | grep "/src/" | wc -l
96
=== automation ===

./bundles/automation/org.eclipse.smarthome.automation.event.test/src/test/groovy/org/eclipse/smarthome/automation/event/RuleEventTest.groovy

./bundles/automation/org.eclipse.smarthome.automation.integration.test/src/test/groovy/org/eclipse/smarthome/automation/integration/test/AutomationIntegrationJsonTest.groovy
./bundles/automation/org.eclipse.smarthome.automation.integration.test/src/test/groovy/org/eclipse/smarthome/automation/integration/test/AutomationIntegrationTest.groovy
./bundles/automation/org.eclipse.smarthome.automation.integration.test/src/test/groovy/org/eclipse/smarthome/automation/integration/test/HostFragmentSupportTest.groovy

./bundles/automation/org.eclipse.smarthome.automation.module.script.test/src/main/groovy/org/eclipse/smarthome/automation/module/script/ScriptRuleTest.groovy
./bundles/automation/org.eclipse.smarthome.automation.module.timer.test/src/test/groovy/org/eclipse/smarthome/automation/module/timer/internal/DayOfWeekConditionHandlerTest.groovy
./bundles/automation/org.eclipse.smarthome.automation.module.timer.test/src/test/groovy/org/eclipse/smarthome/automation/module/timer/internal/RuntimeRuleTest.groovy
./bundles/automation/org.eclipse.smarthome.automation.module.timer.test/src/test/groovy/org/eclipse/smarthome/automation/module/timer/internal/TimeOfDayTriggerHandlerTest.groovy

=== config ===

./bundles/config/org.eclipse.smarthome.config.core.test/src/test/groovy/org/eclipse/smarthome/config/core/normalization/NormalizerTest.groovy
./bundles/config/org.eclipse.smarthome.config.core.test/src/test/groovy/org/eclipse/smarthome/config/core/status/test/ConfigStatusInfoTest.groovy
./bundles/config/org.eclipse.smarthome.config.core.test/src/test/groovy/org/eclipse/smarthome/config/core/status/test/ConfigStatusServiceOSGiTest.groovy
./bundles/config/org.eclipse.smarthome.config.core.test/src/test/groovy/org/eclipse/smarthome/config/core/test/ConfigDescriptionParameterBuilderTest.groovy
./bundles/config/org.eclipse.smarthome.config.core.test/src/test/groovy/org/eclipse/smarthome/config/core/test/ConfigOptionRegistryOSGiTest.groovy
./bundles/config/org.eclipse.smarthome.config.core.test/src/test/groovy/org/eclipse/smarthome/config/core/test/ConfigurationTest.groovy
./bundles/config/org.eclipse.smarthome.config.core.test/src/test/groovy/org/eclipse/smarthome/config/core/validation/test/ConfigDescriptionValidatorTest.groovy
./bundles/config/org.eclipse.smarthome.config.core.test/src/test/groovy/org/eclipse/smarthome/config/core/validation/test/ConfigValidationExceptionTest.groovy

./bundles/config/org.eclipse.smarthome.config.discovery.test/src/test/groovy/org/eclipse/smarthome/config/discovery/inbox/events/InboxEventFactoryTest.groovy
./bundles/config/org.eclipse.smarthome.config.discovery.test/src/test/groovy/org/eclipse/smarthome/config/setup/test/discovery/DiscoveryResultImplTest.groovy
./bundles/config/org.eclipse.smarthome.config.discovery.test/src/test/groovy/org/eclipse/smarthome/config/setup/test/inbox/DynamicThingUpdateOSGITest.groovy
./bundles/config/org.eclipse.smarthome.config.discovery.test/src/test/groovy/org/eclipse/smarthome/config/setup/test/inbox/InboxOSGITest.groovy

./bundles/config/org.eclipse.smarthome.config.xml.test/src/test/groovy/org/eclipse/smarthome/config/xml/test/ConfigDescriptionI18nTest.groovy
./bundles/config/org.eclipse.smarthome.config.xml.test/src/test/groovy/org/eclipse/smarthome/config/xml/test/ConfigDescriptionsTest.groovy

=== core ===

./bundles/core/org.eclipse.smarthome.core.audio.test/src/test/groovy/org/eclipse/smarthome/core/audio/test/AudioConsoleTest.groovy
./bundles/core/org.eclipse.smarthome.core.audio.test/src/test/groovy/org/eclipse/smarthome/core/audio/test/AudioFormatTest.groovy
./bundles/core/org.eclipse.smarthome.core.audio.test/src/test/groovy/org/eclipse/smarthome/core/audio/test/AudioManagerTest.groovy
./bundles/core/org.eclipse.smarthome.core.audio.test/src/test/groovy/org/eclipse/smarthome/core/audio/test/AudioOSGiTest.groovy
./bundles/core/org.eclipse.smarthome.core.audio.test/src/test/groovy/org/eclipse/smarthome/core/audio/test/AudioServletTest.groovy
./bundles/core/org.eclipse.smarthome.core.audio.test/src/test/groovy/org/eclipse/smarthome/core/audio/test/fake/AudioSinkFake.groovy

./bundles/core/org.eclipse.smarthome.core.binding.xml.test/src/test/groovy/org/eclipse/smarthome/core/binding/xml/test/BindingInfoI18nTest.groovy
./bundles/core/org.eclipse.smarthome.core.binding.xml.test/src/test/groovy/org/eclipse/smarthome/core/binding/xml/test/BindingInfoTest.groovy

./bundles/core/org.eclipse.smarthome.core.id.test/src/test/groovy/org/eclipse/smarthome/core/id/UUIDTest.groovy

./bundles/core/org.eclipse.smarthome.core.test/src/test/groovy/org/eclipse/smarthome/core/common/osgi/ResourceBundleClassLoaderGroovyTest.groovy
./bundles/core/org.eclipse.smarthome.core.test/src/test/groovy/org/eclipse/smarthome/core/common/ThreadPoolManagerTest.groovy
./bundles/core/org.eclipse.smarthome.core.test/src/test/groovy/org/eclipse/smarthome/core/events/AbstractEventFactoryTest.groovy
./bundles/core/org.eclipse.smarthome.core.test/src/test/groovy/org/eclipse/smarthome/core/internal/events/OSGiEventManagerOSGiTest.groovy
./bundles/core/org.eclipse.smarthome.core.test/src/test/groovy/org/eclipse/smarthome/core/internal/ItemRegistryOSGiTest.groovy
./bundles/core/org.eclipse.smarthome.core.test/src/test/groovy/org/eclipse/smarthome/core/internal/items/ItemUpdaterOSGiTest.groovy
./bundles/core/org.eclipse.smarthome.core.test/src/test/groovy/org/eclipse/smarthome/core/internal/ItemTagTest.groovy
./bundles/core/org.eclipse.smarthome.core.test/src/test/groovy/org/eclipse/smarthome/core/items/events/AbstractItemEventSubscriberOSGiTest.groovy
./bundles/core/org.eclipse.smarthome.core.test/src/test/groovy/org/eclipse/smarthome/core/items/events/ItemEventFactoryTest.groovy
./bundles/core/org.eclipse.smarthome.core.test/src/test/groovy/org/eclipse/smarthome/core/items/GenericItemTest.groovy
./bundles/core/org.eclipse.smarthome.core.test/src/test/groovy/org/eclipse/smarthome/core/storage/ManagedItemProviderOSGiTest.groovy

./bundles/core/org.eclipse.smarthome.core.thing.test/src/test/groovy/org/eclipse/smarthome/core/thing/binding/BindingBaseClassesOSGiTest.groovy
./bundles/core/org.eclipse.smarthome.core.thing.test/src/test/groovy/org/eclipse/smarthome/core/thing/binding/ChangeThingTypeOSGiTest.groovy
./bundles/core/org.eclipse.smarthome.core.thing.test/src/test/groovy/org/eclipse/smarthome/core/thing/binding/ThingBuilderTest.groovy
./bundles/core/org.eclipse.smarthome.core.thing.test/src/test/groovy/org/eclipse/smarthome/core/thing/binding/ThingFactoryTest.groovy
./bundles/core/org.eclipse.smarthome.core.thing.test/src/test/groovy/org/eclipse/smarthome/core/thing/events/ThingEventFactoryTest.groovy
./bundles/core/org.eclipse.smarthome.core.thing.test/src/test/groovy/org/eclipse/smarthome/core/thing/factory/ManagedThingProviderOSGiTest.groovy
./bundles/core/org.eclipse.smarthome.core.thing.test/src/test/groovy/org/eclipse/smarthome/core/thing/firmware/FirmwareRegistryOSGiTest.groovy
./bundles/core/org.eclipse.smarthome.core.thing.test/src/test/groovy/org/eclipse/smarthome/core/thing/firmware/ProgressCallbackTest.groovy
./bundles/core/org.eclipse.smarthome.core.thing.test/src/test/groovy/org/eclipse/smarthome/core/thing/i18n/ThingStatusInfoI18nLocalizationServiceOSGiTest.groovy
./bundles/core/org.eclipse.smarthome.core.thing.test/src/test/groovy/org/eclipse/smarthome/core/thing/internal/ThingLinkManagerOSGiTest.groovy
./bundles/core/org.eclipse.smarthome.core.thing.test/src/test/groovy/org/eclipse/smarthome/core/thing/internal/ThingManagerOSGiTest.groovy
./bundles/core/org.eclipse.smarthome.core.thing.test/src/test/groovy/org/eclipse/smarthome/core/thing/link/ItemChannelLinkOSGiTest.groovy
./bundles/core/org.eclipse.smarthome.core.thing.test/src/test/groovy/org/eclipse/smarthome/core/thing/link/LinkEventOSGiTest.groovy
./bundles/core/org.eclipse.smarthome.core.thing.test/src/test/groovy/org/eclipse/smarthome/core/thing/ThingPropertiesTest.groovy
./bundles/core/org.eclipse.smarthome.core.thing.test/src/test/groovy/org/eclipse/smarthome/core/thing/ThingUIDTest.groovy
./bundles/core/org.eclipse.smarthome.core.thing.test/src/test/groovy/org/eclipse/smarthome/core/thing/UIDTest.groovy
./bundles/core/org.eclipse.smarthome.core.thing.test/src/test/groovy/org/eclipse/smarthome/core/thing/util/ThingHandlerHelperTest.groovy
./bundles/core/org.eclipse.smarthome.core.thing.test/src/test/groovy/org/eclipse/smarthome/core/thing/util/ThingHelperTest.groovy

=== io ===

./bundles/io/org.eclipse.smarthome.io.rest.core.test/src/test/groovy/org/eclipse/smarthome/io/rest/core/internal/discovery/InboxResourceOSGITest.groovy
./bundles/io/org.eclipse.smarthome.io.rest.core.test/src/test/groovy/org/eclipse/smarthome/io/rest/core/service/test/ConfigurableServiceResourceOSGiTest.groovy

./bundles/io/org.eclipse.smarthome.io.rest.sse.test/src/test/groovy/org/eclipse/smarthome/io/rest/sse/test/SseResourceOSGiTest.groovy

./bundles/io/org.eclipse.smarthome.io.rest.test/src/test/groovy/org/eclipse/smarthome/io/rest/test/filter/CorsFilterTest.groovy
./bundles/io/org.eclipse.smarthome.io.rest.test/src/test/groovy/org/eclipse/smarthome/io/rest/test/filter/ProxyFilterTest.groovy
./bundles/io/org.eclipse.smarthome.io.rest.test/src/test/groovy/org/eclipse/smarthome/io/rest/test/filter/SatisfiableResourceFilterTest.groovy

./bundles/io/org.eclipse.smarthome.io.transport.upnp.test/src/test/groovy/org/eclipse/smarthome/io/transport/upnp/test/UpnpIOServiceTest.groovy

=== model ===

./bundles/model/org.eclipse.smarthome.model.item.tests/src/org/eclipse/smarthome/model/item/internal/GenericItemProviderTest.groovy

./bundles/model/org.eclipse.smarthome.model.thing.tests/src/org/eclipse/smarthome/model/thing/test/hue/TestHueConfigDescriptionProvider.groovy
./bundles/model/org.eclipse.smarthome.model.thing.tests/src/org/eclipse/smarthome/model/thing/tests/GenericItemChannelLinkProviderTest.groovy
./bundles/model/org.eclipse.smarthome.model.thing.tests/src/org/eclipse/smarthome/model/thing/tests/GenericThingProviderTest2.groovy
./bundles/model/org.eclipse.smarthome.model.thing.tests/src/org/eclipse/smarthome/model/thing/tests/GenericThingProviderTest3.groovy
./bundles/model/org.eclipse.smarthome.model.thing.tests/src/org/eclipse/smarthome/model/thing/tests/GenericThingProviderTest4.groovy
./bundles/model/org.eclipse.smarthome.model.thing.tests/src/org/eclipse/smarthome/model/thing/tests/GenericThingProviderTest.groovy

=== storage ===

./bundles/storage/org.eclipse.smarthome.storage.mapdb.test/src/main/groovy/org/eclipse/smarthome/storage/mapdb/StorageServiceOSGiTest.groovy

=== ui ===

./bundles/ui/org.eclipse.smarthome.ui.icon.test/src/test/groovy/org/eclipse/smarthome/ui/icon/test/AbstractResourceIconProviderTest.groovy
./bundles/ui/org.eclipse.smarthome.ui.icon.test/src/test/groovy/org/eclipse/smarthome/ui/icon/test/IconServletTest.groovy

=== binding ===

./extensions/binding/org.eclipse.smarthome.binding.astro.test/src/test/groovy/org/eclipse/smarthome/binding/astro/handler/test/AstroCommandTest.groovy
./extensions/binding/org.eclipse.smarthome.binding.astro.test/src/test/groovy/org/eclipse/smarthome/binding/astro/handler/test/AstroValidConfigurationTest.groovy
./extensions/binding/org.eclipse.smarthome.binding.astro.test/src/test/groovy/org/eclipse/smarthome/binding/astro/test/AstroStateTest.groovy
./extensions/binding/org.eclipse.smarthome.binding.astro.test/src/test/groovy/org/eclipse/smarthome/binding/astro/test/cases/AstroBindingTestsData.groovy
./extensions/binding/org.eclipse.smarthome.binding.astro.test/src/test/groovy/org/eclipse/smarthome/binding/astro/test/cases/AstroParametrizedTestCases.groovy

./extensions/binding/org.eclipse.smarthome.binding.hue.test/src/test/groovy/org/eclipse/smarthome/binding/hue/test/HueBridgeHandlerOSGiTest.groovy
./extensions/binding/org.eclipse.smarthome.binding.hue.test/src/test/groovy/org/eclipse/smarthome/binding/hue/test/HueLightHandlerOSGiTest.groovy

./extensions/binding/org.eclipse.smarthome.binding.wemo.test/src/main/groovy/org/eclipse/smarthome/binding/wemo/discovery/test/WemoDiscoveryOSGiTest.groovy
./extensions/binding/org.eclipse.smarthome.binding.wemo.test/src/main/groovy/org/eclipse/smarthome/binding/wemo/discovery/test/WemoDiscoveryParticipantTest.groovy
./extensions/binding/org.eclipse.smarthome.binding.wemo.test/src/main/groovy/org/eclipse/smarthome/binding/wemo/discovery/test/WemoLinkDiscoveryServiceOSGiTest.groovy
./extensions/binding/org.eclipse.smarthome.binding.wemo.test/src/main/groovy/org/eclipse/smarthome/binding/wemo/handler/test/WemoHandlerOSGiTest.groovy
./extensions/binding/org.eclipse.smarthome.binding.wemo.test/src/main/groovy/org/eclipse/smarthome/binding/wemo/handler/test/WemoHandlerTest.groovy
./extensions/binding/org.eclipse.smarthome.binding.wemo.test/src/main/groovy/org/eclipse/smarthome/binding/wemo/handler/test/WemoLightHandlerOSGiTest.groovy
./extensions/binding/org.eclipse.smarthome.binding.wemo.test/src/main/groovy/org/eclipse/smarthome/binding/wemo/handler/test/WemoMakerHandlerOSGiTest.groovy
./extensions/binding/org.eclipse.smarthome.binding.wemo.test/src/main/groovy/org/eclipse/smarthome/binding/wemo/internal/http/test/WemoHttpCallOSGiTest.groovy
./extensions/binding/org.eclipse.smarthome.binding.wemo.test/src/main/groovy/org/eclipse/smarthome/binding/wemo/test/GenericWemoLightOSGiTest.groovy
./extensions/binding/org.eclipse.smarthome.binding.wemo.test/src/main/groovy/org/eclipse/smarthome/binding/wemo/test/GenericWemoOSGiTest.groovy

=== Groovy test environment ===

./bundles/test/org.eclipse.smarthome.test/src/main/groovy/org/eclipse/smarthome/test/AsyncResultWrapper.groovy
./bundles/test/org.eclipse.smarthome.test/src/main/groovy/org/eclipse/smarthome/test/OSGiTest.groovy

If we keep our current pace the migration will be completed in February 2022 😁

@sjka's pure optimism, as always 🤣

$ find . -name "*.groovy" | grep "/src/" | wc -l
51

The 51 files are part of 16 bundles

$ find . -name "*.groovy" | grep "/src/" | sed 's:\(.*\)/src/.*:\1:g' | sort -u
./bundles/automation/org.eclipse.smarthome.automation.event.test
./bundles/automation/org.eclipse.smarthome.automation.module.script.test
./bundles/automation/org.eclipse.smarthome.automation.module.timer.test
./bundles/config/org.eclipse.smarthome.config.core.test
./bundles/config/org.eclipse.smarthome.config.discovery.test
./bundles/config/org.eclipse.smarthome.config.xml.test
./bundles/core/org.eclipse.smarthome.core.audio.test
./bundles/core/org.eclipse.smarthome.core.binding.xml.test
./bundles/core/org.eclipse.smarthome.core.id.test
./bundles/core/org.eclipse.smarthome.core.thing.test
./bundles/io/org.eclipse.smarthome.io.rest.core.test
./bundles/io/org.eclipse.smarthome.io.rest.sse.test
./bundles/io/org.eclipse.smarthome.io.rest.test
./bundles/model/org.eclipse.smarthome.model.item.tests
./bundles/model/org.eclipse.smarthome.model.thing.tests
./bundles/ui/org.eclipse.smarthome.ui.icon.test

Thanks @wborn for your recent cleanups:

  • 43 Groovy files
  • 10 bundles that contains Groovy files

When the open Groovy to Java migration PRs are merged @maggu2810 , the remaining Groovy file and bundle counts should be 0. :smile:

After that I think we could do a final cleanup of documentation, infra (e.g. OSGiTest) and other leftovers to get this issue closed.

Thank you for your amazing migration work.

I could try to do some further cleanup of the base pom.xml the next days.

final cleanup of documentation, infra (e.g. OSGiTest)

Note that the groovy base test classes are still in use by others (see https://github.com/eclipse/smarthome/issues/6183), so we should keep them in place for backward compatibility, but certainly not recommend anybody to use them anymore.

With #6187 merged and #6191 for tracking the final groovy clean up we can close here.
Thank you all for the hard work!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

airix1 picture airix1  ·  3Comments

mhilbush picture mhilbush  ·  3Comments

afuechsel picture afuechsel  ·  9Comments

jvivanco28 picture jvivanco28  ·  5Comments

doandzhi picture doandzhi  ·  6Comments