Skip to content

Empty rule verification should not apply to noMethods/noClasses #806

Closed
@pkubowicz

Description

#774 should not be executed for rules written using noMethods/noClasses. Otherwise those methods make no sense: I want to guard against illegal code appearing in my codebase. If there is no code matching what I the rule defines, it's a success, not an error.

Imagine I have a rule checking I don't write broken JUnit 5 tests:

@AnalyzeClasses(packages = ["com.example"])
class ArchitectureTest {
    @ArchTest
    val noVoidTestFactory = noMethods().that().areAnnotatedWith("org.junit.jupiter.api.TestFactory")
        .should().haveRawReturnType("void")
}

Now some bad code:

class SomeTest {
    @Test
    fun helloWorld() {
        println("ok")
    }

    @TestFactory
    fun wrong() {
        println("I will be never executed")
    }
}

The architecture test detects this bad code. But now fix the bad test: remove wrong method together with its annotation. The architecture test will start to fail (with com.tngtech.archunit:archunit-junit5:0.23.0):

Rule failed to check any classes. This means either that no classes have been passed to the rule at all, or that no classes passed to the rule matched the `that()` clause. To allow rules being evaluated without checking any classes you can set the ArchUnit property archRule.failOnEmptyShould = false

This is a regression in 0.23.0. The architecture rule worked correctly in 0.22.0.

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