Details
-
Sub-task
-
Status: Closed
-
TBD
-
Resolution: Fixed
-
None
-
None
-
High
Description
Context
openmrs-core has a lot of tests. You can categorize them for example into tests that
- do not extend any test base class like public class ProviderTest { ; unit test
- do extend the BaseContextMockTest like public class ModuleExtensionsTest extends BaseContextMockTest { ; unit test
- 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.
Strategy
These changes will only be done to the tests in the openmrs-api subproject.
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.
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.
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.
Migrate all remaining Junit 4 tests to 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.
Remove powermock from test dependencies of the api package since it does not support JUnit 5.
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
- https://github.com/openmrs/openmrs-core/commit/06c9129e2ebaf32e46736495fe07b34ecfd06a4d
- https://github.com/openmrs/openmrs-core/commit/9ddba4575317c65795b0846783b1f9a58a39f610
- https://github.com/openmrs/openmrs-core/commit/0a9f1854ccc847955602c2212e67bc7baf7b1414
- https://github.com/openmrs/openmrs-core/commit/68f17d66bdf2849978e09d69a0570b88b69f0c9d use MockitoExtension which allows constructor, parameter injection of mocks and is strict by default enabling cleaner tests
- https://github.com/openmrs/openmrs-core/commit/a7aee4bf0bc3455124dff6a62b7857b0c7514b97 updated IntelliJ live templates to write up to date Junit 4 and 5 tests
- https://github.com/openmrs/openmrs-core/commit/dda2f3e30cb6af46a8c7b8b5766b208ad6e1b60d first integration tests merged
- https://github.com/openmrs/openmrs-core/commit/e886f7038ab9039b6e6679c2072a49687f87442c updated Eclipse code templates to write up to date Junit 4 and 5 tests
- https://github.com/openmrs/openmrs-core/commit/b61e6e6699441b8fe7a804cbb7d44f84863f3a1a migrated more unit tests
- https://github.com/openmrs/openmrs-core/commit/5cb01f9a55dc498cdc8197dc375db33f13867887
- https://github.com/openmrs/openmrs-core/commit/b3d2fab879ab757f8c1798fe3fce0041b10fc5d6
- https://github.com/openmrs/openmrs-core/commit/6cde7661dc3318ec692453ef8638a95abdaef2cd
- https://github.com/openmrs/openmrs-core/commit/89e3c22efdbb1e57ce27df1b97485ebb0d18b978
- https://github.com/openmrs/openmrs-core/commit/2e82ea6586a6b687fc392faab24f379f72db3b7d
- https://github.com/openmrs/openmrs-core/commit/e3b1d06cc494a60617a2304412b8d47b89b5a2b0
- https://github.com/openmrs/openmrs-core/commit/64a3d12f4a3d8be776c3977396f7bb97037d0069
- https://github.com/openmrs/openmrs-core/commit/188df04dc3424302ec13f6ce40029a570de7b9c7
- https://github.com/openmrs/openmrs-core/commit/0f87146c751519429d4734ff722eff1ee1197101
- https://github.com/openmrs/openmrs-core/commit/39f9059f2f7cdd57260de8393cb50dbc04631ed9
- https://github.com/openmrs/openmrs-core/commit/e02183887a9e503d79794873f838d89848db0869
- https://github.com/openmrs/openmrs-core/commit/46360a939d90d991d452e6a42479e060d73a7f82
- https://github.com/openmrs/openmrs-core/commit/41665fd864c6b43af841d4199bfd889ab9a3faa3 migrated some PropertyEditors and the BasePropertyEditorTest
- https://github.com/openmrs/openmrs-core/commit/3a7d59c9e464c09d691bdac61516853ecbfdd862
- https://github.com/openmrs/openmrs-core/commit/0b16dd5046c6ce70242da2e9f7017dba329af6df BasePropertyEditorTest only supported in JUnit 5
- https://github.com/openmrs/openmrs-core/commit/ee01136e97c58e6616336f79756ca8d9faaeb7e2 make BasePropertyEditorTest package private
- https://github.com/openmrs/openmrs-core/commit/aa598541834154d728256478ad10e1fcc7ecc4f2
- https://github.com/openmrs/openmrs-core/commit/a8905ca49ba5023e84b25ec4d8416dc3b69274f0
- https://github.com/openmrs/openmrs-core/commit/e2298ad2106940f5526418ff00dd903b003872f8
- https://github.com/openmrs/openmrs-core/commit/a1d3424b48118441be545f7517548a13e575d13b Provide JUnit5 StartModuleExecutionListener
- https://github.com/openmrs/openmrs-core/commit/a1d3424b48118441be545f7517548a13e575d13b Make JUnit5 StartModuleExecutionListener package private
- https://github.com/openmrs/openmrs-core/commit/35b8c95a29da288d30d1e6ad4621018e56fbbb83
- https://github.com/openmrs/openmrs-core/commit/0a754b343f94f01bf6a4abdf6976faec506f0516 transition AllergyValidatorTest away from PowerMock since PowerMock is not supported in JUnit 5
- https://github.com/openmrs/openmrs-core/commit/de7bfbb8f84ccf82ea5fd4e934c7a9ba9e483f31 remove AllergyValidatorTest javadocs
- https://github.com/openmrs/openmrs-core/commit/b6985ae3b7cb72770aabe350c904b21a73e00c2b
- https://github.com/openmrs/openmrs-core/commit/357e320dce7f237381cd06f604dcf7aeb8304861
- https://github.com/openmrs/openmrs-core/commit/03db57deff4ee94bc36d5bcef41af115cf22b229
- https://github.com/openmrs/openmrs-core/commit/d2ba259a93746db7c6d33bc12e13f1134594cbe5
- https://github.com/openmrs/openmrs-core/commit/12ceeacd4f7b3ff5769855e6b50e8303bc822845 BaseModuleActivator test copied to JUnit 5 for now (since its also used in the openmrs-web)
- https://github.com/openmrs/openmrs-core/commit/22c5bae9281755303e8b14dcb38c3694a2c7740a
- https://github.com/openmrs/openmrs-core/commit/4a96fa2fed6a363685b09a66b0ebb0a85e38c300
- https://github.com/openmrs/openmrs-core/commit/8ceeaecdf8309ffbd48edfa2a3bc1f58c5cbecf7
- https://github.com/openmrs/openmrs-core/commit/1093eabecc3e7da6db0658873ab856e054977546
- https://github.com/openmrs/openmrs-core/commit/0ee2d1f6bcde882268a76062efef640b8360e088 close streams so TempDir can delete all files on Windows see discussion https://talk.openmrs.org/t/tests-failing-in-core/29471/23 and error logs https://pastebin.com/UstUVqHk
- https://github.com/openmrs/openmrs-core/commit/ca23425a3c6688edeee13a9609418f96e3865110
- https://github.com/openmrs/openmrs-core/commit/bc4adc1efaa488c889d3fd2ab61f8178b7e704b4 do not allow PowerMock tests to be run
- https://github.com/openmrs/openmrs-core/commit/d5585afd4142a3facb1d12340e0c4588f0db6565 only depend on powermock.reflect
- https://github.com/openmrs/openmrs-core/commit/aff6a214fe2a2ed3fe6da29799fc12eef21e94a2 temporarily disable failing HandlerTests on Windows see https://talk.openmrs.org/t/tests-failing-in-core-on-windows/29471/16
- https://github.com/openmrs/openmrs-core/commit/7481583d88a189d795cae83767536f9caec26cbd Run StartModuleAnnotationTest
- https://github.com/openmrs/openmrs-core/commit/c29a802fa97e1ab784cef8c3d75546a76ff3d702 Make StartModuleExecutionListener JUnit independend
- https://github.com/openmrs/openmrs-core/commit/9671c340cf314dc45b89fa79e8acb1c8dabff1b9 Port fix of StartModuleExecutionListener to JUnit 5 one
- https://github.com/openmrs/openmrs-core/commit/cb59c583153ccc22f59aafd17a26e69bd519dd10 Test StartModuleAnnotation on JUnit 4 & 5
- https://github.com/openmrs/openmrs-core/commit/18c9c2a4c5a922c56aab240cdf9401441ff1b3ce Add JUnit 4 & 5 tests for BaseContext / '@StartModule' helpers
- https://github.com/openmrs/openmrs-core/commit/7cffb3746f55dad924a816075e6a9ac150b330df Do not allow JUnit 4 tests to be added
- https://github.com/openmrs/openmrs-core/commit/58635cf8593a80cca75659a91124844a4c64f2ea use MockitoExtension in BaseContextSensitiveTest
Gliffy Diagrams
Attachments
Issue Links
- is related to
-
TRUNK-3064 Create unit test for duplicate messages
-
- Closed
-
- links to