Skip to content

Commit d52ba67

Browse files
SirCotareclaude
andcommitted
document the current API and the opt-out annotations
The usage section still described the 1.1.0 API (extends ArchitectureTestBase, a BLACKLISTED_CLASSES static block), which no longer exists. Replaces it with the rule collections, records why no rule allows an empty selection, and documents both opt-out annotations - neither of which any consumer appears to use yet. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
1 parent 630fab9 commit d52ba67

1 file changed

Lines changed: 34 additions & 10 deletions

File tree

readme.md

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,32 +18,56 @@ Add this library to the classpath by adding the following maven dependency. Vers
1818

1919
## Usage
2020

21-
To use this package, simply extend one of the provided ArchUnit classes.
22-
For example `ArchitectureTestBase`:
21+
Implement one of the provided rule collections in your own architecture test.
2322

2423
```java
2524

2625
@AnalyzeClasses(
2726
packages = ArchitectureTest.PACKAGE
2827
)
2928
@NullMarked
30-
class ArchitectureTest extends ArchitectureTestBase {
29+
@ArchIgnoreNoProductionCounterpart
30+
class ArchitectureTest implements BaseArchRuleCollection {
3131
static final String PACKAGE = "the.base.package.of.your.project";
32-
33-
static {
34-
// Configuration
35-
}
3632
}
3733
```
3834

39-
In the static block you can configure some blacklists provided by the base class.
35+
`BaseArchRuleCollection` holds the rules that apply to any Java project. `CommonArchRuleCollection`
36+
adds rules for Spring MVC controllers and for `SortMappings`, so implement it only in a project that
37+
has them.
38+
39+
The blacklists are mutable, so a project can drop an entry it disagrees with:
4040

4141
```java
42-
static {
43-
ArchitectureTestBase.BLACKLISTED_CLASSES.remove("net.datafaker.Faker");
42+
43+
static {
44+
BlacklistClassesArchRule.BLACKLISTED_CLASSES.remove("net.datafaker.Faker");
4445
}
4546
```
4647

48+
The same applies to `ArchRuleConfig.TEST_CLASS_SUFFIXES` when a project introduces a new test type.
49+
50+
### Every rule must be able to fail
51+
52+
No rule uses `allowEmptyShould(true)`. A rule that selects nothing would otherwise report success,
53+
which is indistinguishable from a rule that is satisfied - and that is how a broken rule survives
54+
unnoticed. So a rule whose selection comes up empty fails, and the fix is either to remove the rule
55+
collection you do not need or to add the code it is meant to check.
56+
57+
### Opting out
58+
59+
Two annotations exempt a class from a specific rule. Neither is meta-annotated with ArchUnit's
60+
`@ArchIgnore`: the ArchUnit JUnit engine resolves meta-annotations, so that would skip *every*
61+
`@ArchTest` on the annotated class and report success rather than exempting it from one rule.
62+
63+
| annotation | put it on | exempts from |
64+
|---|---|---|
65+
| `@ArchIgnoreNoProductionCounterpart` | a test class | needing a production class of the same name in the same package, and having its `@Nested` classes matched against production methods |
66+
| `@ArchIgnoreGroupName` | a `@Nested` test class | needing a production method of the same name, for a class that only groups tests |
67+
68+
Use `@ArchIgnoreNoProductionCounterpart` for a test named after the behaviour it describes rather than
69+
after a production class, and on your own `ArchitectureTest`.
70+
4771
## Local Development
4872

4973
To use this library as a local development dependency, you can simply refer to the version `BUILD-SNAPSHOT`.

0 commit comments

Comments
 (0)