Wiki Spaces
Documentation
Projects
Resources
Get Help from Others
Q&A: Ask OpenMRS
Discussion: OpenMRS Talk
Real-Time: IRC Chat | Slack
This guide should help you as a module developer to migrate your tests to JUnit 5. If you are not yet convinced that you should migrate read on. If you are jump straight to the next section.
WORK IN PROGRESS
openmrs-core - TRUNK-5811Getting issue details... STATUS JUnit 5 tests have just been migrated to JUnit 5 and will be supported from the release of 2.4.0 on. Your JUnit 4 tests will still run without any change from your side.
You will only be able to migrate all your tests once the above task is marked as done.
So the information here is preliminary and might also change.
openmrs-core tests just migrated (as of release 2.4.0) from JUnit 4 to JUnit 5 - TRUNK-5811Getting issue details... STATUS
JUnit 5 has been released on Sep 10, 2017. JUnit 4 is still maintained and thus receives updates. At some point it will have reached its end of life. New developers with some Java experience coming to OpenMRS from other projects will very likely have written tests in JUnit 5. Since JUnit 5 is the current version and out since Sep 2017. JUnit 5 offers a lot of interesting new feature that we can leverage. An incomplete list of interesting features
The JUnit team has provided great support for teams to gradually migrate over to JUnit 5. When updating openmrs-core our goal was to provide the same to you as module developers.
This means that once you update your dependency on openmrs-core (TODO and most likely also openmrs-test) to 2.4.x you will be able to
If you are interested in some background information on the migration from the JUnit team see https://junit.org/junit5/docs/current/user-guide/#migrating-from-junit4
We used IntelliJ IDEA 2020.1.3 (Community Edition) since it provides a migration tool that automates most steps.
org.junit.Assert.assertThat
with org.hamcrest.MatcherAssert.assertThat.
Use IntelliJ search & replace within the entire project. Read more on the why at https://issues.openmrs.org/browse/TRUNK-5812ExpectedException
or @Test(expected = APIException.class
) with the assertThrows JUnit 4 method. Try using IntelliJ Structural search & replace within the entire project. See discussion on talk about example usages. Read more on the why at https://issues.openmrs.org/browse/TRUNK-5813mvn dependency:tree
to display the project dependencies in tree format.Make sure these dependencies are present. JUnit (4.x → 5.0)
migration as shown below
If you want to see a video of how the migration feature works see