Repository navigation
Run mojo tests on JUnit 5 with the project built from their POM - #1423
Merged
Merged
Conversation
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
force-pushed
the
agent/junit5-harness
branch
from
October 10, 2026 18:29
343d222 to
fb0cc7e
Compare
This was referenced Oct 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:MojoExtensiongives the mojo an empty spiedMavenProjectand 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-003sets<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.ProjectMojoExtensionextendsMojoExtensionand overrides onlylookupMojo: it copies the directory of the@InjectMojoPOM to a temporary directory, builds the copy with the container'sProjectBuilder, 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, notsrc/test/resources.@ProjectMojoTestregisters 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:
@Basedir.-Dortest.propertiesare set with@MojoParameter, so they go through the same binding.ItRepositorybuilds the mock repository fromsrc/it-repo, the repository the ITs used, instead of version lists copied into each class.TextAssertionsmethods are renamed to say they are about text:assertTextContains,assertTextNotContains,assertTextContainsInOrder,assertTextMatches(whole text),assertTextContainsPatternandassertTextNotContainsPattern(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 thedependencyExcludesparameter or changing an expected version makes the test fail;src/test/resourcesis unchanged after the run