Comments (2)
Resolved by #128
from archunit.
I take it, you're not using the JUnit 4 support, are you? Because then you could simply aggregate Tests like
public class MyAggregatedRules {
@ArchTest
public static final ArchRules rules1 = ArchRules.in(FirstRuleSuite.class);
@ArchTest
public static final ArchRules rules2 = ArchRules.in(SecondRuleSuite.class);
}
(which works recursively, this is how we compose SpecificRules
-> LessSpecificRules
-> AllRules
-> ConcreteTest
)
This will work with the JUnit 5 support as well, once it's finished.
But if you're writing your tests as plain unit tests, ArchRules
is not usable in a comfortable way, you're right about that. You can add something like this yourself in the following way:
public class RuleSuite implements ArchRule {
private final List<ArchRule> rules;
private String overriddenDescription;
public RuleSuite(ArchRule... rules) {
checkArgument(rules.length > 0, "A suite of 0 rules makes no sense");
this.rules = Arrays.asList(rules);
}
@Override
public void check(JavaClasses classes) {
Assertions.check(this, classes);
}
@Override
public ArchRule because(String reason) {
rules.get(rules.size() - 1).because(reason);
return this;
}
@Override
public EvaluationResult evaluate(JavaClasses classes) {
EvaluationResult result = new EvaluationResult(this, Priority.MEDIUM);
for (ArchRule rule : rules) {
result.add(rule.evaluate(classes));
}
return result;
}
@Override
public String getDescription() {
if (overriddenDescription != null) {
return overriddenDescription;
}
List<String> descriptions = new ArrayList<>();
for (ArchRule rule : rules) {
descriptions.add(rule.getDescription());
}
return Joiner.on(lineSeparator() + " and ").join(descriptions);
}
@Override
public ArchRule as(String newDescription) {
overriddenDescription = newDescription;
return this;
}
}
This will join all rule descriptions and after that join all errors of all rules in one shot, instead of failing after the first.
I have pondered about making ArchRules
usable in plain unit tests in a pretty similar fashion, but I have to see what the requirements of the JUnit test support are, once I'm done with the JUnit 5 support (since it was originally composed for that).
I think you're right though, that ArchUnit should offer a way out of the box to create such composite rules, even it no extra testing support is used. I'll think about it, where this could be added the best (whether it's ArchRules
or another composite similar to the one above).
I hope you can use that POC for now though for your use case, let me know if you have trouble!!
from archunit.
Related Issues (20)
- Enforce ArchTests when module is depended upon HOT 1
- Compatibility issue with logback-classic 1.4.12 HOT 2
- ClassFileImporter fails to load classes with synthetic methods HOT 2
- The tests are running too late HOT 2
- [BUG] Calling getEnclosingClass() on a nested class does provide a JavaClass with no members HOT 2
- fails with Spring Boot Nested Jars HOT 11
- getCallsOfSelf does not return calls made through interface reference HOT 4
- Add method support for function callMethod HOT 2
- Get modifiers of JavaParameter HOT 1
- Layer dependency rule ignores "catch" blocks
- Enum classes not recognized as enums and with with wrong access modifiers HOT 3
- Wrong line numbers and constructor call order
- JavaType#getAllInvolvedRawTypes() throws StackOverflowError with self-referential generic types HOT 2
- @AnalyzeClasses breaks JUnit 5 tag filtering HOT 3
- Is there a way to know if JavaCodeUnit is a switch/case statement? HOT 4
- Custom Error Messages for StoreUpdateFailedException
- Remove false positives from Transactional Proxy Rule HOT 2
- question about calling line numbers HOT 3
- Using MethodReferences is still breaking soundness HOT 5
- Usability: Java confuses the static and non-static versions of DescribedPredicate.and() when using the API the wrong way. HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from archunit.