Skip to content

Maven ignores tests defined as ArchTest fields #1157

@Scaronthesky

Description

@Scaronthesky

I'm under the impression that Maven seems to ignore ArchUnit tests which are defined as fields with the @archtest annotation.

I copied some of the CodingRulesTest from the ArchUnit-Examples project, e. g. "No Access to Standard streams". These tests work fine when I execute them with IntelliJ. Maven completely ignores them, though. Maven executes only tests which are defined as "proper" test methods.

Is this a configuration issue or a bug? I had a look at the documentation and issues but could not find anything.

import static com.tngtech.archunit.library.GeneralCodingRules.NO_CLASSES_SHOULD_ACCESS_STANDARD_STREAMS;
import com.tngtech.archunit.core.domain.JavaClasses;
import com.tngtech.archunit.junit.AnalyzeClasses;
import com.tngtech.archunit.junit.ArchTest;
import com.tngtech.archunit.lang.ArchRule;

@AnalyzeClasses(packages = "de.package")
public class CodingRulesTest {

  // Will silently be ignored by Maven
  @ArchTest
  public final ArchRule no_access_to_standard_streams = NO_CLASSES_SHOULD_ACCESS_STANDARD_STREAMS;

  // Will be executed
  @ArchTest
  public void assertNoAccessToStandardStreams(JavaClasses classes) {
    NO_CLASSES_SHOULD_ACCESS_STANDARD_STREAMS.check(classes);
  }
}

In the examples project the ArchRule fields are private. I made the public but it makes no difference. They are still ignored.

maven-surefire-plugin:3.1.2
Using configured provider org.apache.maven.surefire.junitplatform.JUnitPlatformProvider
com.tngtech.archunit:archunit-junit5-api:1.1.0
com.tngtech.archunit:archunit-junit5-engine:1.1.0
org.junit.jupiter:junit-jupiter-api:5.10.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions