openmrs-core junit 5 migration status

Hi friends of a good test :sunny:

I will not have access to a computer for a few weeks and thus wanted to give you a status report of the JUnit 5 migration of openmrs-core.

I will be able to respond on talk / review a few things on GitHub but I cannot try things out myself. I hope the community will support @achilep so we can get the migration over the finish line :slight_smile:

What we have achieved:

Here is what is left in my opinion:

  • 2 tests are failing on Windows (are disabled on Windows but run on any other OS thus Travis CI/Bamboo CI). Either the tests have a flaw, there is an actual bug or the API we are testing does not make it easy to do the right thing. For more, on what we think is the cause and what we tried see tests failing in core on Windows

  • adapt javadocs of helper classes to signal deprecation and transition to JUnit 5

  • Migrate a module so we uncover any other unknown issues and show how module devs can migrate https://issues.openmrs.org/browse/TRUNK-5818

  • Finish the migration guide, incorporate feedback from the first brave module devs migrating to JUnit 5

  • Update the Unit Testing docs relating Assertions. I already adopted/flagged the deprecated JUnit 4 APIs; we need to adapt package names. Probably provide JUnit 4 & 5 package names for important things. Since some devs will still work on JUnit 4 tests outside of openmrs-core.

  • I think we do not have tests in openmrs-core that test the test helpers like @StartModule, BaseModuleContextSensitiveTest, BaseModuleWebContextSensitiveTest from the modules perspective. @StartModule at least when I look on GitHub in the openmrs org does not seem to be used often but still. Our APIs should be tested so we ensure it works for our consumers. We cannot write a test extending BaseModuleContextSensitiveTest in the api or web package since it would create another ehCache with name hibernateCache. You can only have one per JVM with this name.

And very important: not reintroduce JUnit 4 tests into openmrs-core. I added a test that checks tests for the JUnit 4 @Test. It should fail if anyone tries to add such a test. If you need to add a JUnit 4 test for backwards compatibility reasons for module devs you will need to add it to the exclusion list. We cannot yet remove the JUnit 4 dependency since we allow module devs to migrate at their own pace. So we provide JUnit 4 & 5 BaseModuleContextSensitiveTest, BaseModuleWebContextSensitiveTest

Thank you for your support and patience with the occasional hiccup of a failing pipeline.

JUnit 5 has some great features we can familiarize ourselves with and start using. Here is only a handful to get you excited :grinning:

4 Likes

Thanks alot @teleivo for your great work in this period of GSOC i could say you came back in a very good time. We surely going to continue to support @achilep as you have been to supportive in junit5 migration with your guidance/review thanks alot

2 Likes

well done @teleivo ,sure we will support @achilep

1 Like

hello , sorry for silence . we are a little stuck at this level : https://github.com/openmrs/openmrs-core/pull/3392 any suggestion is welcome. cc @dkayiwa @ibacher @bistenes @mozzy

1 Like

How exactly are you blocked on that pull request?

1 Like

Sorry for delay @dkayiwa , we are trying to rewrite UpdateFilterModelTest.java without powermock using java reflection , because powermock has no equivalent in junit 5 .From there it will be easier to convert it to junit 5 .

we have support from @wolf :slight_smile: we just need to give him some more time to look into it

3 Likes

that great @teleivo

1 Like

Thanks @teleivo and @achilep for the ton of work on this

1 Like

Hello , We are currently at this level . I have a little concern :

  1. How can i access our helpers https://github.com/openmrs/openmrs-core/tree/master/api/src/test/java/org/openmrs/test/jupiter from openmrs-module-webservices when the version of the core-api that contain this helpers have not yet been release ? .

  2. How can we migrate for example : omod-1.10 to junit 5 when the version of the openmrs test that it depend (openmrs.version.1.10) is in junit 4 . (knowing that openmrs.version.1.10 don’t have our new helpers ) ?

thanks

cc : @teleivo @ibacher @dkayiwa @sharif @mozzy

Please, My intention is not to migrate the whole openmrs-module-webservices but use it as an example .

Can you use this as the example? https://github.com/openmrs/openmrs-module-webservices.rest/tree/master/omod-2.4

2 Likes

yes, thanks @dkayiwa , but same i have the same issue with this version omod-2.4 instead of omod-1.10.

Which exact issue do you have with omod-2.4?

I assume the current openmrs-core is released as 2.4.0-SNAPSHOT

and then web services omod-2.4 depends on this SNAPSHOT version

see

1 Like

I do not seem to understand the issue that @achilep finds with that. :slight_smile:

thanks @teleivo @dkayiwa i found myself :grin:. the issue was with this class BaseModuleWebContextSensitiveTest :grinning: . This PR will solve the issue : https://github.com/openmrs/openmrs-core/pull/3445 , @dkayiwa i took into consideration that BaseModuleWebContextSensitiveTest is use out of openmrs. If it is not the case, then i will not duplicate the class .