Arc unit test
1. What is ArchUnit?
Answer:
ArchUnit is an open-source Java testing library used to validate and enforce application architecture rules (e.g., layered architecture, naming conventions, dependency rules) through unit-like tests.
3. What architectural violations are most important to catch with ArchUnit in enterprise systems?
Ideal Answer
Cyclic dependencies between modules
Service-to-service direct DB calls
Cross-domain leakage (bounded context breaches)
Avoiding util-god packages
Only domain layer uses domain entities
Enforce hexagonal architecture (ports/adapters)
REST controllers don’t call repositories directly
4. What type of rules can we enforce with ArchUnit?
Answer:
Layered architecture rules
Package structure rules
Naming conventions
Class dependency restrictions
Annotation usage rules
Cyclic dependency detection
2. Why do we use ArchUnit?
Answer:
To enforce architectural standards
Prevent bad dependencies
Ensure layered structure (Controller → Service → Repository)
Detect cyclic dependencies early
Improve long-term maintainability
9. Can we integrate ArchUnit with CI/CD?
Answer:
Yes — run ArchUnit tests as part of your normal test pipeline in Maven/Gradle CI tools like GitHub Actions, Jenkins, GitLab CI, etc.10. What happens when rules fail?
Answer:
The test fails with a descriptive message, preventing merge/deployment if enforced in CI.11. Difference between ArchUnit and SonarLint/SonarQube?
ArchUnit SonarLint/SonarQube Developer-defined rules Built-in + custom rules Architecture test at unit level Mostly static code quality Runtime JUnit test Static code scan 3. How do you add ArchUnit dependency?
Answer:
Maven
Comments
Post a Comment