Skip to content

Migrate tests from JUnit 4 to JUnit 5#247

Merged
dkayiwa merged 2 commits intomasterfrom
migrate-junit4-to-junit5
Mar 9, 2026
Merged

Migrate tests from JUnit 4 to JUnit 5#247
dkayiwa merged 2 commits intomasterfrom
migrate-junit4-to-junit5

Conversation

@dkayiwa
Copy link
Member

@dkayiwa dkayiwa commented Mar 8, 2026

Summary

Migrates all ~70 test files in the omod module from JUnit 4 to JUnit 5 (Jupiter) to align with openmrs-core 3.0.0-SNAPSHOT which has completed its JUnit 5 migration.

Changes

Import migrations

  • org.junit.Testorg.junit.jupiter.api.Test
  • org.junit.Assertorg.junit.jupiter.api.Assertions
  • org.junit.Before / @Beforeorg.junit.jupiter.api.BeforeEach / @BeforeEach
  • org.junit.After / @Afterorg.junit.jupiter.api.AfterEach / @AfterEach
  • org.junit.Ignore / @Ignoreorg.junit.jupiter.api.Disabled / @Disabled
  • junit.framework.Assertorg.junit.jupiter.api.Assertions
  • org.junit.Assert.assertThatorg.hamcrest.MatcherAssert.assertThat
  • org.mockito.Matchersorg.mockito.ArgumentMatchers

Base test class updates

  • org.openmrs.web.test.BaseModuleWebContextSensitiveTestorg.openmrs.web.test.jupiter.BaseModuleWebContextSensitiveTest
  • org.openmrs.web.test.BaseWebContextSensitiveTestorg.openmrs.web.test.jupiter.BaseWebContextSensitiveTest

Pattern replacements

  • @Rule ExpectedExceptionAssertions.assertThrows()
  • @Test(expected = X.class)Assertions.assertThrows()
  • JUnit 4 assertion message parameter order (first → last)

Build configuration

  • Upgraded maven-surefire-plugin from 2.22.1 to 3.5.2
  • Added aligned JUnit Platform 6.0.3 dependencies to resolve version mismatch with JUnit Jupiter 6.0.3

Mockito cleanup

  • Removed unnecessary stubs causing UnnecessaryStubbingException under JUnit 5's stricter Mockito defaults

Test results

Tests run: 366, Failures: 0, Errors: 0, Skipped: 3
BUILD SUCCESS

dkayiwa and others added 2 commits March 8, 2026 23:31
- Replace all JUnit 4 imports with JUnit 5 Jupiter equivalents
  (org.junit.Test → org.junit.jupiter.api.Test, etc.)
- Update @before@beforeeach, @ignore@disabled
- Switch BaseModuleWebContextSensitiveTest and BaseWebContextSensitiveTest
  to their jupiter package variants
- Replace @rule ExpectedException and @test(expected=...) with assertThrows()
- Fix assertion parameter order (message moved from first to last arg)
- Replace deprecated org.mockito.Matchers with org.mockito.ArgumentMatchers
- Replace org.junit.Assert.assertThat with org.hamcrest.MatcherAssert.assertThat
- Remove unnecessary Mockito stubs causing UnnecessaryStubbingException
- Upgrade maven-surefire-plugin from 2.22.1 to 3.5.2
- Add aligned JUnit Platform 6.0.3 dependencies to fix version mismatch

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Reorder 3-arg assertNotSame in ConceptFormControllerTest to JUnit 5
  parameter order (unexpected, actual, message)
- Use containsString instead of is matcher in
  RegexValidatedTextDatatypeHandlerTest to preserve the original
  substring-matching behavior of ExpectedException.expectMessage()

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@dkayiwa dkayiwa merged commit 60dc887 into master Mar 9, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant