ArchUnit is a Java testing library that lets you enforce architectural rules as JUnit tests. Five practical examples are shown: preventing service/repository layers from depending on the web layer, enforcing layered architecture access rules, banning Spring field injection in favor of constructor injection, enforcing class naming conventions, and restricting usage to JUnit 5 only. The DSL reads like plain English, making the rules easy to understand and maintain alongside the codebase.
Table of contents
Rule 1: Services and Repositories should not talk to Web layerRule 2: Should follow Layered ArchitectureRule 3: Spring’s @Autowired should NOT be used with Field based injectionRule 4: Should follow Naming conventionRule 5: Should use JUnit 5 onlySort: