TNG / ArchUnit

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

failOnEmptyShould conflicts with optionalLayer #809

Closed bjpe closed 2 years ago

bjpe commented 2 years ago

Hi, I have an ArchUnit test for a layered architecture, which has some mandatory layers and some optional layers, which are currently empts (i.e., there are no classes in the referred package).

This works fine with ArchUnit 0.22.0, but after an update to ArchUnit 0.23.0 I got

java.lang.AssertionError: 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

Removing the access restriction for the optional, empty layer fixes the test, as well as setting

archRule.failOnEmptyShould=false

but without this property the optional layers seem not so optional anymore.

codecholeric commented 2 years ago

Thanks for raising this, it seems to go into the same direction as #803, #806 and #808 :+1: But I also see that there is an additional component, because layered architecture is composed from multiple sub-rules we need to watch out to in any case set each optional layer sub-rule to allow empty should, no matter what the configuration says. /cc @oberprah