• Sub-task
    • Status: Closed
    • TBD
    • Resolution: Fixed
    • None
    • Core 2.4.0
    • None
    • High



      openmrs-core has a lot of tests. You can categorize them for example into tests that

      1. do not extend any test base class like public class ProviderTest { ; unit test
      2. do extend the BaseContextMockTest like public class ModuleExtensionsTest extends BaseContextMockTest { ; unit test
      3. do extend the BaseContextSensitiveTest like public class PersonDAOTest extends BaseContextSensitiveTest { ; technically integration test since it relies on an in-memory DB

      We also have tests that rely on the Junit 4 rule @Rule public TemporaryFolder temporaryFolder = new TemporaryFolder();} which does not exist in Junit 5. It has been replaced with Extension TempDir

      We might also use Junit 4 in unexpected ways. You can find articles/discussions/tweets on how Junits internal APIs have been (mis)used making it hard for projects to upgrade.

      These are all reasons why such a migration contains risks and not everything can be foreseen.

      We therefore chose to first migrate only tests within the api package. This allows us to gain confidence that openmrs-core can migrate all of its tests. This also ensures that we do not make any change to the dependencies of openmrs-test project before. openmrs-test is depended upon modules. So before making any change to it we should be confident in our setup.


      These changes will only be done to the tests in the openmrs-api subproject.

      1. Add Junit 5 dependencies that allow running Junit 4 and 5 tests side by side. Migrate a few unit tests that do not extend any of the above mentioned helpers.
      2. Migrate a few tests that extend the BaseContextMockTest. Include a test that relies on the @Rule public TemporaryFolder so we can test the Extension TempDir. Note: we need to keep BaseContextMockTest since module developers will get ample time to migrate so we need to support them to run Junit 4 & 5 tests.
      3. Migrate a few tests that extend the BaseContextSensitiveTest. Note: we need to keep BaseContextSensitiveTest since module developers will get ample time to migrate so we need to support them to run Junit 4 & 5 tests.
      4. Migrate all remaining Junit 4 tests to 5
      5. We still have Junit 3 references in the api package. These are imports of junit.framework. Replace all of these by jupiter imports/methods. junit.framework classes are coming from the JUnit 4 dependency. To prevent JUnit 3 tests from being written we need to remove the JUnit 4 dependency.
      6. Remove powermock from test dependencies of the api package since it does not support JUnit 5.
      7. Added a test that prevents new JUnit 4 tests from being added to the api package

      Junit 5 allows us to easily migrate to it also because classes, annotations replacing the ones in JUnit 4 have the same name but are simply in another package called org.junit.jupiter. This is why the IntelliJ migration tool only needs to change imports for example for the @Test

      We can follow the same approach end provide BaseContext... classes in a new package called org.openmrs.test.jupiter. When api tests or module tests migrate they just need to update the import and everything else should work as before.

      Commited Code

      Collecting commits here since there will be quite a few and are harder to find in a long list of comments

      Gliffy Diagrams


          Issue Links



                achilep Pahonsi Bebeto Achile
                achilep Pahonsi Bebeto Achile
                0 Vote for this issue
                2 Start watching this issue