javagradlejunit5archunit

How to configure Gradle to pickup ArchUnit tests via @Tag annotation?


When I tried to integrate ArchUnit into our setup, I noticed that ArchUnit tests were not being picked up by Gradle.

Our Gradle config contains several testing tasks to separate UnitTests, IntegrationTests, and AcceptanceTests. Those tasks only pick up tagged classes:

test {
    useJUnitPlatform {
        includeTags "UnitTest"
    }
}

It appears that ArchUnit tests are not being picked up despite being tagged correctly.

@Tag("UnitTest")
@AnalyzeClasses(packages = "com.example", importOptions = {ImportOption.DoNotIncludeTests.class})
public class ArchTests {
    ...
}

When I invert the includeTags to excludeTags the ArchUnit tests are being picked up.

test {
    useJUnitPlatform {
        excludeTags "IntegrationsTest", "AcceptanceTest"
    }
}

How can I configure Gradle/ArchUnit to preserve the include notion?


Solution

  • Does this message from ArchUnit issue 1238 help?

    @Tag is actually from the JUnit Jupiter API, while ArchUnit is a completely different JUnit 5 engine that just builds on the JUnit platform. As such ArchUnit will never react to things that come from org.junit.jupiter. However, ArchUnit offers almost the same API, you just have to use @ArchTag instead of @Tag. It should behave very similar to @Tag in all respects.