Skip to content

Run mojo tests on JUnit 5 with the project built from their POM - #1423

Merged
slachiewicz merged 1 commit into
masterfrom
agent/junit5-harness
Oct 10, 2026
Merged

slachiewicz merged 1 commit into
masterfrom
agent/junit5-harness

Conversation

@slachiewicz

@slachiewicz slachiewicz commented Oct 10, 2026 •

Copy link
Copy Markdown
Member

Part of #1414. The JUnit 4 harness (AbstractMojoTestCase, MojoRule) is deprecated, and its JUnit 5 replacement in maven-plugin-testing-harness 3.5.1 cannot run our POM-based tests as is: MojoExtension gives the mojo an empty spied MavenProject and evaluates the mojo parameters against it. The POM's dependencies, inherited versions and interpolation are missing, and so are POM properties that set parameters; it-003 sets <processDependencies>false</processDependencies> and lists the dependency when that is lost. 3.5.1 is the last 3.x release and the 3.x branch still mocks the project.

ProjectMojoExtension extends MojoExtension and overrides only lookupMojo: it copies the directory of the @InjectMojo POM to a temporary directory, builds the copy with the container's ProjectBuilder, loads the model, original model, file, parent and artifact into the project the harness uses, and lets the harness configure the mojo as before. Goals that rewrite the POM change the copy, not src/test/resources. @ProjectMojoTest registers it in place of @MojoTest.

The three scenario classes added in #1416, #1417 and #1418 move to it, and with that off JUnit 4 and Hamcrest:

  • POMs are named by path under a class-level @Basedir.
  • Parameters the old ITs passed with -D or test.properties are set with @MojoParameter, so they go through the same binding.
  • ItRepository builds the mock repository from src/it-repo, the repository the ITs used, instead of version lists copied into each class.
  • The TextAssertions methods are renamed to say they are about text: assertTextContains, assertTextNotContains, assertTextContainsInOrder, assertTextMatches (whole text), assertTextContainsPattern and assertTextNotContainsPattern (anywhere in the text).

The other 24 classes on the JUnit 4 harness follow in separate PRs.

Verified: mvn -pl versions-maven-plugin clean install -Dinvoker.skip → 297 tests, the same count as on master, 0 failures, 0 Checkstyle violations, no deprecation warning from the new classes; removing the dependencyExcludes parameter or changing an expected version makes the test fail; src/test/resources is unchanged after the run

@slachiewicz slachiewicz added the maintenance Cleanup, refactoring or other internal change label Oct 10, 2026
@slachiewicz
slachiewicz marked this pull request as ready for review October 10, 2026 18:11
The harness's JUnit 5 MojoExtension hands the mojo an empty project and
evaluates parameters against it, so POM dependencies and POM properties
that set parameters are lost. ProjectMojoExtension builds a copy of the
POM first and loads it into that project. The scenario tests take their
versions from src/it-repo and their parameters from @MojoParameter.
Part of #1414.
@slachiewicz
slachiewicz merged commit 113774e into master Oct 10, 2026
15 checks passed
@slachiewicz
slachiewicz deleted the agent/junit5-harness branch October 10, 2026 19:20
@github-actions github-actions Bot added this to the 2.22.1 milestone Oct 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintenance Cleanup, refactoring or other internal change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant