Questions tagged [archunit]

ArchUnit is a free, simple and extensible library for checking the architecture of your Java code. That is, ArchUnit can check dependencies between packages and classes, layers and slices, check for cyclic dependencies and more.

ArchUnit is a free, simple and extensible library for checking the architecture of your Java code. That is, ArchUnit can check dependencies between packages and classes, layers and slices, check for cyclic dependencies and more. It does so by analyzing given Java bytecode, importing all classes into a Java code structure. ArchUnit's main focus is to automatically test architecture and coding rules, using any plain Java unit testing framework.

https://github.com/TNG/ArchUnit

Description taken from the project's GitHub page.

116 questions
34
votes
2 answers

How to ignore classes in test class with ArchUnit

I wrote my first ArchUnit test: import static com.tngtech.archunit.library.dependencies.SlicesRuleDefinition.*; // more non-static imports @RunWith(ArchUnitRunner.class) @AnalyzeClasses(packages = "my.domain.project") public class…
Jens Schauder
  • 77,657
  • 34
  • 181
  • 348
10
votes
0 answers

How can I automatically enforce JavaScript architectural/dependency rules?

We are writing a JavaScript application that is becoming large. We have a few architectural rules that we would like to be able to enforce, the main use case would be something like: package A cannot require package B. In a Java application, you…
7
votes
4 answers

Is there any library like arch unit for Django?

I've been searching for a library or tool to test my Django project architecture, check the dependencies, layers, etc. like Arch Unit for Java. But until now, I didn't find anything. I don't even know if it's viable doing these kinds of tests in…
Yuri Costa
  • 199
  • 9
7
votes
3 answers

How to exclude a class in an ArchUnit rule?

While creating a rule for a layered architecture in ArchUnit, it's not clear to me how to exclude a single class (Main). The base example excludes with a source and a target. ... but I don't get how it converts to my need. I just want just Main to…
Luís Soares
  • 5,726
  • 4
  • 39
  • 66
5
votes
1 answer

ArchUnit / test architecture for Flutter or Dart

I'm developing an Flutter App using Clean Architecture. Now i'm looking for a library or something else like ArchUnit. To test the architecture and to ensure the correct access of packages. How do you solve the problem and ensure compliance with the…
TOho
  • 320
  • 4
  • 9
5
votes
1 answer

Search for unused classes in ArchUnit, how to find MyClass.class reference?

I'm trying to make a unit test with ArchUnit to check if I have any unused classes. But I can't figure out how to check if some class is referenced with MyClass.class. For example I have a class: public class MyClass { ... } Then I reference…
Mika K
  • 101
  • 4
4
votes
2 answers

ArchUnit - ensure method parameters are annotated

I'm trying to write an ArchUnit test rule, which should ensure that interfaces annotated with @ComponentInterface annotation have method parameters annotated with @Input annotation. Like this: ArchRule rule = methods() .that() …
manuna
  • 729
  • 14
  • 37
4
votes
1 answer

Checking the architecture of your Clojure code with unit tests

I have been inspired buy this book: Building Evolutionary Architectures and clean architecture. One of the concept is to be able to test your architecture in the code. In particular I would like to be able to check dependencies between namespaces,…
Michel Uncini
  • 321
  • 1
  • 14
3
votes
1 answer

Archunit package A can't access package B, except subpackage A.X can access B.Y

We are in the process of refactoring our code to a hexagonal architecture, with each domain in the code being a separate gradle module. Currently all the code is one module with a package for each domain, and modules interacting with eachother…
3
votes
2 answers

Classes and packages encapsulation in an hexagonal architecture

I would like to know if in Java (JDK 17) there is a way to easily handle classes and packages encapsulation in an hexagonal architure. I would like to make unavailable classes present in an adapter to the domain. To illustrate my goal, say we have…
akuma8
  • 4,160
  • 5
  • 46
  • 82
3
votes
1 answer

How to exclude a package from Archunit Tests?

In my root project I have two sub projects with that package structure. Project 1: com.app Project 2: com.app.api In Project 1 I have a Class definied with ArchRules, anotaed like that @AnalyzeClasses( packages = "com.app") public class…
Tristate
  • 1,498
  • 2
  • 18
  • 38
3
votes
0 answers

How to define arch rule to prohibit that classes catch specific exception types?

I wish I could define an arch rule prohibiting that classes catch a given exception type. Something like the rule below: noClasses() .that() .resideOutsideOfPackage("..repository..") .should() .catchExceptions() .that() …
EijiAdachi
  • 441
  • 1
  • 3
  • 15
3
votes
3 answers

ArchUnit: How to avoid dependency violation to java classes

I want to verify, that classes within a given package, only refer to classes that reside in the package itself. However I get a violation, telling me that the a class depends on e.g. java.lang.String, which is totally ok for me. Is there a way to…
bertolami
  • 2,896
  • 2
  • 24
  • 41
3
votes
3 answers

How to validate that a method annotation is using an attribute with an specific value using archunit

I have an @Audit annotation, it has many optional attributes, I need to enforce the use of one boolean attribute useAccount = true for certain packages. I am trying to use archunit to accomplish this validation, that way whenever a developer commits…
raspacorp
  • 5,037
  • 11
  • 39
  • 51
2
votes
1 answer

ArchUnit test sensitive variable naming

Setup: 17 2.7.0 5.8.2
d.braun1991
  • 151
  • 1
  • 13
1
2 3 4 5 6 7 8