TNG / ArchUnit

A Java architecture test library, to specify and assert architecture rules in plain Java
http://archunit.org
Apache License 2.0
3.17k stars 287 forks source link

@AnalyzeClasses breaks JUnit 5 tag filtering #1238

Closed coulas closed 5 months ago

coulas commented 7 months ago

Hello, First, thank you for your great work ! You are awesome :-)

Second, I was using a field of type ClassFileImporter and a @Tag("toRefactor") on my test classes to define some groups of tests. My pom.xml use surefire configured with a group attribute to select the groups I want.

When I switched from a JavaClasses field to @AnalyzeClasses, the tag filtering did not work anymore. I need tag filtering to separate breaking tests (functional and architecture validation) and non-breaking tests (list of refactoring in progress).

Does a JUnit5 tag's support is possible ?

RefactoringTest.java

@Tag("toRefactor")
//@AnalyzeClasses(packagesOf = TcsApplication.class, importOptions = { ImportOption.DoNotIncludeTests.class, ImportOption.DoNotIncludeArchives.class })
class RefactoringTest implements SpringShapeShould {
  private final JavaClasses javaClasses = new ClassFileImporter(List.of(DO_NOT_INCLUDE_TESTS, DO_NOT_INCLUDE_ARCHIVES)).importPackages(getBaseApplicationPackageName());
  [...rest of test file ...]

Pom.xml:

[... "a few lines" ...]
  <build>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-surefire-plugin</artifactId>
      <version>3.2.3</version>
      <configuration>
        <groups>!toRefactor</groups>
      </configuration>
    </plugin>
  <build>
  <profiles>
    <profile>
      <id>refactoring</id>
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>3.2.3</version>
            <configuration>
              <testFailureIgnore>true</testFailureIgnore>
              <groups>toRefactor</groups>
            </configuration>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>
</project>
codecholeric commented 7 months ago

Glad you like ArchUnit 😄 @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.

codecholeric commented 5 months ago

Did this solve your problem?

codecholeric commented 5 months ago

Closing this for now, feel free to reopen if your issue persists!