JUnit 4 support removed in Platform 3.0.0 — Module migration required

Hi everyone,

As part of Platform 3.0.0, we’ve completed the JUnit 4 → JUnit 5 migration in openmrs-core (PR #5894 ( Complete JUnit 4 to JUnit 5 migration by dkayiwa · Pull Request #5894 · openmrs/openmrs-core · GitHub )).

This means:

  • The deprecated JUnit 4 base test classes (org.openmrs.test.BaseContextSensitiveTest, BaseContextMockTest, etc.) have been deleted

  • junit:junit and junit-vintage-engine have been removed from the BOM

  • JUnit 4 tests will no longer compile against Platform 3.0.0

What module developers need to do:

1. Replace org.openmrs.test.BaseContextSensitiveTest → org.openmrs.test.jupiter.BaseContextSensitiveTest (same for all base classes)

2. Replace @org.junit.Test → @org.junit.jupiter.api.Test (and other annotations)

3. Update assertion imports from org.junit.Assert → org.junit.jupiter.api.Assertions

A full migration guide with step-by-step instructions and a troubleshooting table is available at: doc/JUNIT5_MIGRATION.md (openmrs-core/doc/JUNIT5_MIGRATION.md at master · openmrs/openmrs-core · GitHub)

The JUnit 5 equivalents have been available since Platform 2.4, so most actively maintained modules may already be migrated. If you run into issues, please ask here.

3 Likes

Thanks @dkayiwa . I would be great if someone could create a list of modules that still require upgrading, and then we can bang through it. Seems like something AI could assist with, if it is mostly just boilerplate replacement of packages and classes with alternative equivalents? Would be great if we could save individuals the effort of doing this line by line on their individual modules.

Are we planning on upgrading to JUnit 6? My understanding is that there’s no migration for Jupiter tests.

I’m pretty sure no modules have moved from JUnit 4 to 5, though some modules may have had newer tests implemented in 5.

Very good point. Just done that.

We are planning to do this for all the reference application modules.

For AI coding agents, this is definitely a piece of cake. :smiley:

Even for things that are not just boilerplate replacement of packages, a good agent coupled with a good model, and then provided with the appropriate context, these tools are unbelievably awesome!!! :smiley:

1 Like

@mseaton i threw this to an AI coding agent with a prompt to just ensure that the module compiles without any errors or test failures. It figured out that the problem came from dropping JUnit 4 support in core 3.0.0-SNAPSHOT and it raised this pull request: Migrate all tests from JUnit 4 to JUnit 5/6 by dkayiwa · Pull Request #715 · openmrs/openmrs-module-webservices.rest · GitHub

With the same exact prompt, the agent opened another pull request for the legacyui module: Migrate tests from JUnit 4 to JUnit 5 by dkayiwa · Pull Request #247 · openmrs/openmrs-module-legacyui · GitHub

2 Likes

That’s great @dkayiwa - what was the prompt and agent?

This is the exact prompt: fix all errors until when running mvn clean install succeeds without a single compiler error or failing test. After which you will open a pull request

The agent was GitHub Copilot using the Claude Opus 4.6 model. I just fired up two agents in parallel on command line with the same exact prompt, and continued with my other tasks. They notified me when they were done with the above pull requests.

1 Like