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

How to fail tests if no classes are imported? #1325

Open bbadjari opened 3 months ago

bbadjari commented 3 months ago

Is there a convenient way to fail tests when no classes are imported via ClassFileImporter? I found some old tests that continued to pass even though they were doing nothing useful because ClassFileImporter was attempting to import classes from a package (via the importPackages() method) that no longer existed.

hankem commented 3 months ago

Since #774 (released with ArchUnit 0.23.0), ArchUnit can Fail Rules on Empty Should, i.e. when the should-part of rules is evaluated against an empty set of classes, which should catch your case.

You're not accidentially using an archunit.properties file with archRule.failOnEmptyShould=false (or even a very old version of ArchUnit), are you?