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.

47 questions
20
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
  • 65,795
  • 24
  • 148
  • 294
9
votes
0 answers

What is the ArchUnit equivalent in the JavaScript ecosystem?

ArchUnit is a free, simple and extensible library for checking the architecture of your Java code using any plain Java unit test framework. That is, ArchUnit can check dependencies between packages and classes, layers and slices, check for cyclic…
5
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
  • 4,466
  • 1
  • 27
  • 47
3
votes
1 answer

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
  • 129
  • 8
3
votes
0 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
  • 463
  • 8
  • 27
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
  • 421
  • 1
  • 3
  • 14
3
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
  • 71
  • 4
3
votes
0 answers

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
  • 305
  • 1
  • 13
2
votes
2 answers

ArchUnit doesnt seem to cache analyzed classes

I wrote some ArchUnit-Tests using Jupiter. I found examples that indicated, you can write your ArchUnit tests using non static methods, like: @Test void enforceExceptionNames() { classes().that() .areAssignableTo(Exception.class) …
Mathe S
  • 41
  • 4
2
votes
1 answer

Is it possible to check if method is declared in a group of classes?

I'm using ArchUnit and I want to check if all classes residing in a package declare one only public method called execute. I have this code: JavaClasses importedClasses = new ClassFileImporter().importPackages("my.package"); …
Héctor
  • 19,875
  • 26
  • 98
  • 200
2
votes
1 answer

How do I create an ArchUnit rule to verify all exceptions thrown inherit from a specific custom exception?

One of my architecture rules is that all exceptions thrown by the application code must be either CustomException, or a subclass of CustomException. I am having difficulty writing this rule in ArchUnit. What I have currently is the…
beer geek
  • 149
  • 9
2
votes
1 answer

ArchUnit to test actual layered architecture

Currently in our project we have layered architecture implemented in following way where Controller, Service, Repository are placed in the same package for each feature, for…
fashuser
  • 1,972
  • 24
  • 44
2
votes
2 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,836
  • 2
  • 22
  • 40
1
vote
1 answer

How to enforce SLF4J usage in Java code with ArchUnit

I wanna use ArchUnit to enforce usage only SLF4J logging framework and avoid simple System.out calls. Also I would like to avoid any other logging frameworks for using. How can I implement the such check? Currently I write this test class…
Andriy Kryvtsun
  • 2,766
  • 1
  • 22
  • 32
1
vote
2 answers

What is the difference between members and fiels in archunit

I wondering what's the difference between members() and fields() in ArchUnit. I can't find any documentation about it.
niels
  • 7,144
  • 2
  • 33
  • 56
1
2 3 4