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
0
votes
0 answers

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
  • 148
  • 3
  • 9
0
votes
1 answer

Can ArchUnit check for certain string patterns in method calls?

In our code we again and again have the issue that somebody forgot to adapt the usage of placeholders when switching between the use of the logger and String.format(...) methods. For log statements one has to use '{}' as placeholders, like…
mmo
  • 3,165
  • 8
  • 35
  • 49
0
votes
1 answer

ArchUnit: Create a rule based on class imports

I would like to create an ArchUnit rule which will not allow to use so called starred (*) imports in my project. Can I achieve this in ArchUnit?
0
votes
1 answer

ArchUnit layer test: how to exclude a specific class?

Is there the possibility to exclude a specific class from a layered test-condition in an ArchUnit-test? I have packages A, B, C, D defined as follows: +- A <-- contains a factory class referring to B, C and D. +-B +-C …
mmo
  • 3,165
  • 8
  • 35
  • 49
0
votes
0 answers

Possible to specify tests that ALWAYS run?

I am implementing ArchUnit on a Java project. This is a set of rules that run against your codebase as part of unit tests, that detect violations of your application architecture. I'm setting up the ArchUnit rules to run as a JUnit 5 test. When…
beer geek
  • 149
  • 9
0
votes
1 answer

ArchUnit: how to test for imports of specific classes outside of current package?

To externalize UI strings we use the "Messages-class" approach as supported e.g. in Eclipse and other IDEs. This approach requires that in each package where one needs some UI strings there has to be a class "Messages" that offers a static method…
mmo
  • 3,165
  • 8
  • 35
  • 49
0
votes
2 answers

ArchUnit: cyclic dependency for generics not detected

ArchUnit 0.14.1 did not detect cyclic dependencies for types that are used as parameters for generic fields. Is that a limitation in ArchUnit or am I doing something wrong? , e. g.: package com.test.a; import com.test.b.B; public class A { …
StCR
  • 3
  • 3
0
votes
1 answer

Test package dependencies within a module with ArchUnit

I have trouble formulating the following test with ArchUnit: I want to ensure that all classes in a certain package only access classes outside of the application base package or within a certain sub package ("or" not "xor"). What I have got…
robbit
  • 197
  • 1
  • 7
0
votes
1 answer

ArchUnit rule to test @Service only depends on @Repository in own package?

I'd like to write an ArchUnit rule that validates that a service class (Annoted by the @Service Spring annotation) will only use a repository from its own package, not from other packages. I currently have: noClasses().that() …
Wim Deblauwe
  • 19,439
  • 13
  • 111
  • 173
0
votes
1 answer

ArchUnit: How to check for unwanted dependecies in the signature / API of a class?

I would like to implement an ArchUnit rule that checks for unwanted dependencies. That's easy to do but I'm only interested in violations that are part of the signature / API of the class. E.g. if the class uses an unwanted dependency in a private…
0
votes
1 answer

How can I assert if a class extends "AnyVal" using ArchUnit

I want to write an arch unit test to assert that a class extends AnyVal type. val rule = classes().should().beAssignableTo(classOf[AnyVal]) val importedClasses = new ClassFileImporter().importPackages("a.b.c") isAnyVal.check(importedClasses) //…
tusharmath
  • 9,120
  • 11
  • 52
  • 70
0
votes
1 answer

Checking annotation presence in subclasses with ArchUnit

I'm evaluating ArchUnit 0.13.1 with JUnit 5 and try to write a rule like: @ArchTest private final ArchRule annotationInheritance = ArchRuleDefinition.classes() .that().areAnnotatedWith(MyAnnotation.class) …
Holger
  • 355
  • 3
  • 10
0
votes
1 answer

ArchUnit classes should depend only on particular classes from a package

I have two separate packages: mycomp.sales - Order - OrderPlaced mycom.delivery - Delivery - OrderPlacedListener (depends on mycomp.sales.OrderPlaced) I want to set a rule which checks that the package mycom.delivery has only a dependency on…
Barney
  • 617
  • 5
  • 16
0
votes
0 answers

How to enforce private parameters in constructors in Kotlin with ArchUnit?

I have this class: class CreateUser(private val userRepo: UserRepository) { fun execute(user: User) { userRepo.save(user) } } I have this test: @Test fun `private dependencies at constructors`() { constructors() …
Luís Soares
  • 4,466
  • 1
  • 27
  • 47
0
votes
1 answer

ArchUnit case insensitive name matching

I'm trying to setup tests with Arch Unit to test my naming conventions, following the official examples. It seems ArchUnit's naming assertions are case sensitive, which is bothering me. I want to test that no classes in the package domain.service…
Gauthier
  • 2,945
  • 1
  • 16
  • 31