Skip to content

Add support for JUnit6#1659

Open
schulzjo-tng wants to merge 8 commits into
mainfrom
feature/junit6-with-test-coverage
Open

Add support for JUnit6#1659
schulzjo-tng wants to merge 8 commits into
mainfrom
feature/junit6-with-test-coverage

Conversation

@schulzjo-tng

@schulzjo-tng schulzjo-tng commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

@arukiidou

arukiidou commented Jul 9, 2026

Copy link
Copy Markdown

Part 1 and Part 2 are almost identical.
If possible, I recommend cherry-picking from Part 2.

Only the following three things should be different:

  • It starts over again from the addition of the shared tests
  • The commits have been split into smaller ones to make things easier
  • example-test has been added

@schulzjo-tng
schulzjo-tng force-pushed the feature/junit6-with-test-coverage branch 2 times, most recently from 25a25d8 to c9660f2 Compare July 9, 2026 14:33
@schulzjo-tng
schulzjo-tng force-pushed the feature/junit6-with-test-coverage branch 2 times, most recently from 9998433 to dabea23 Compare July 10, 2026 13:57
Comment thread archunit-junit/build.gradle
Comment thread archunit-maven-test/verification/TestResultTest.java
Comment thread archunit-maven-test/build.gradle
Comment thread archunit-maven-test/build.gradle
Comment thread archunit-maven-test/build.gradle

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved to archunit-self-test/src/main/java/com/tngtech/archunit/ArchUnitExampleArchitectureRules.java with too many changes

Comment thread archunit-self-test/build.gradle
Comment thread buildSrc/src/main/groovy/archunit.self-test-conventions.gradle
@schulzjo-tng
schulzjo-tng force-pushed the feature/junit6-with-test-coverage branch from dabea23 to 75512aa Compare July 10, 2026 14:32
Comment thread archunit-maven-test/build.gradle Outdated
Comment thread archunit-maven-test/verification/TestResultTest.java
Comment thread archunit-integration-test/junit6/build.gradle Outdated
Comment thread buildSrc/src/main/groovy/archunit.self-test-conventions.gradle Outdated
Comment thread buildSrc/src/main/groovy/archunit.self-test-conventions.gradle Outdated
Comment thread archunit/src/archTest/java/com/tngtech/archunit/ArchUnitArchitectureTest.java Outdated
Comment thread archunit-self-test/src/main/java/com/tngtech/archunit/PublicAPIRules.java Outdated
Comment thread archunit/src/archTest/java/com/tngtech/archunit/ArchUnitArchitectureTest.java Outdated
Comment thread archunit/src/archTest/java/com/tngtech/archunit/ArchUnitArchitectureTest.java Outdated
Comment thread archunit-self-test/build.gradle Outdated
Comment thread buildSrc/src/main/groovy/archunit.self-test-conventions.gradle Outdated
@schulzjo-tng
schulzjo-tng force-pushed the feature/junit6-with-test-coverage branch 8 times, most recently from 0db3de2 to 4194a2c Compare July 24, 2026 13:14
.ignoreDependency(ArchConfiguration.class, ClassResolver.class);
.ignoreDependency(ArchConfiguration.class, ClassResolver.class)
// Not all layers are present on all archunit-junit* packages
.withOptionalLayers(true);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hankem this setting is not covered by archRule.failOnEmptyShould=false. We can either set this withOptionalLayers or self-check the entirety of ArchUnit in all production packages (i.e. @AnalyzeClasses(packages = "com.tngtech.archunit" instead of @AnalyzeClasses(packages = "com.tngtech.archunit.junit.[...]"). What would you prefer?

@schulzjo-tng
schulzjo-tng force-pushed the feature/junit6-with-test-coverage branch 3 times, most recently from 4b5b3e4 to d24f652 Compare July 24, 2026 18:31
@schulzjo-tng
schulzjo-tng marked this pull request as ready for review July 24, 2026 18:32
arukiidou and others added 5 commits July 25, 2026 10:43
Introduce `archunit-junit6-api`, `archunit-junit6-engine`, `archunit-junit6-engine-api`
as well as the `archunit-junit6` aggregator modules (analogous to their junit5 counterparts)
to enable ArchUnit tests on the JUnit 6 platform:

* Implement `ArchUnitTestEngine` and `ArchUnitTestDescriptor` for test discovery and execution.
* Add `ArchTest`, `AnalyzeClasses`, and `ArchTag` annotations to define and organize tests.
* Implement `ArchUnitSystemPropertyTestFilterJUnit6`
  to support test filtering via the `junit.testFilter` system property.

Signed-off-by: junya koyama <arukiidou@yahoo.co.jp>
Co-authored-by: Dr. Jonathan Schulz <jonathan.schulz@tngtech.com>
Signed-off-by: Dr. Jonathan Schulz <jonathan.schulz@tngtech.com>
Using version catalog for Maven plugins
(`mavenSurefirePlugin` and `mavenCompilerPlugin` from `gradle/libs.versions.toml`
 are injected into `archunit-maven-test/pom.xml.template` via `archunit-maven-test/build.gradle`).

`TestResultTest` now identifies test results by simple class names
since the behavior of the maven-surefire-plugin
changed with apache/maven-surefire#214:
`surefire-junit-platform/src/main/java/org/apache/maven/surefire/junitplatform/RunListenerAdapter.java`
uses `className = testPlan.getParent(testIdentifier).getDisplayName()`
instead of `org.junit.platform.launcher.listeners.LegacyReportingUtils.getClassName(testPlan, testIdentifier)`
for `TestSource`s that are neither a `MethodSource` nor a `ClassSource`
(including ArchUnit's `FieldSource`, created by `ArchUnitRuleDescriptor`),
which causes the test report's testcase/@classname to not contain fully qualified class names anymore.

Signed-off-by: Dr. Jonathan Schulz <jonathan.schulz@tngtech.com>
Add `archunit-example:example-junit6` (analogous to `archunit-example:example-junit5`),
and `archunit-integration-test:junit6` (analogous to `archunit-integration-test:junit5`) to verify them.

Signed-off-by: Dr. Jonathan Schulz <jonathan.schulz@tngtech.com>
- Required because the previous setting was unable to test junit5-engine and junit6-engine at the same time

Signed-off-by: Dr. Jonathan Schulz <jonathan.schulz@tngtech.com>
This task caused build failures on Windows. After some investigation,
I concluded that it is no longer needed - the existing `dependencies.exclude()`
make this transformation an identity operation. Also, there is test coverage
for missing `exclude` statements (see `:checkArtifact`), so we can't accidentally
publish a release where the problem that this code meant to address is present.

Signed-off-by: Dr. Jonathan Schulz <jonathan.schulz@tngtech.com>
Comment on lines +14 to +15
archTestImplementation project(path: ':archunit-junit4')
archTestImplementation project(path: ':archunit-junit5')

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need both, right?

Suggested change
archTestImplementation project(path: ':archunit-junit4')
archTestImplementation project(path: ':archunit-junit5')
archTestImplementation project(path: ':archunit-junit5')

can obtain the necessary JAR files directly from
http://search.maven.org/#search%7Cga%7C1%7Cg%3A%22com.tngtech.archunit%22[Maven Central].

=== JUnit 4

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we flip the order of JUnit 4 and JUnit 5 & 6?
The sequence of 4, 5, 6 is nice, but JUnit 4 might be(come) less relevant.

schulzjo-tng and others added 3 commits July 25, 2026 17:53
Signed-off-by: Dr. Jonathan Schulz <jonathan.schulz@tngtech.com>
… be allow-listed

Signed-off-by: Dr. Jonathan Schulz <jonathan.schulz@tngtech.com>
@hankem
hankem force-pushed the feature/junit6-with-test-coverage branch from d24f652 to f695eaf Compare July 25, 2026 16:08

@hankem hankem left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the effort! 💙

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.

3 participants