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)
- 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
- Unable to find the JavaAccess call HOT 8
- Feature suggestion: Freeze files and stored.rules validation / sanity check
- How To : validate return type is not `void` HOT 2
- How To : Is there way to filter classes when using `importJar()` HOT 1
- DEPRECATED_API_SHOULD_NOT_BE_USED does not consider constants nor final fields HOT 2
- ASM is not up-to-date
- Jakarta Inject package name incorrect in BE_ANNOTATED_WITH_AN_INJECTION_ANNOTATION rule HOT 1
- How can I find out which gradle module a class belongs to HOT 7
- Problem with maven multi module project HOT 2
- False positive results when I use ArchRuleDefinition.noClasses() HOT 7
- Check access classes only works for some cases HOT 1
- ArchUnit do not correctly check Annotation on enum Constants HOT 2
- ArchUnit thinks "Switch with arrows" produces non-final fields HOT 1
- Feature suggestion: Expose synchronized blocks in core API
- Performance: archunit-junit5 may scan complete JDK for `@ArchTest`
- SimpleName-Check failing because of trailing file extension (Kt) HOT 6
- ArchUnits - get name of lambda method HOT 1
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.