ArchUnit
ArchUnit copied to clipboard
Allow `@AnalyzeClasses` to be used as a meta annotation
Having @AnalyzeClasses allowed to be a meta annotation would allow one to encapsulate repeating options across tests:
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@AnalyzeClasses(packages = {PACKAGE_X, PACKAGE_Y}, importOptions = {DoNotIncludeTests.class, DoNotIncludeJars.class, DoNotIncludeArchives.class})
public @interface AnalyzeStandardClasses
For similar features in Spring, checkout https://docs.spring.io/spring/docs/current/spring-framework-reference/testing.html#integration-testing-annotations-meta.
Sounds like a reasonable addition :smiley: Would be worth it to ponder about the implications if several @AnalyzeClasses come together then. I.e.
@AnalyzeUi
@AnalyzeService
class MyGeneralArchRules {
@ArchTest
static final ArchRule firstRule = // ...
}
Because up to now this scenario was impossible by design. I guess since all the members of @AnalyzeClasses are varargs anyway, it would be easy to just aggregate all @AnalyzeClasses within the hierarchy and add all the varargs together. This means addition of locations to import and intersection of ImportOptions though...
Also the use of two different cache modes would be a question to solve, who would win if one @AnalyzeClasses wants to clear the cache after the run and one wants to keep it? The safe thing would be to use the shorter one I guess.
I'll see if anyone wants to pitch in a PR here since I have to work on some other issues first.
Is this something that can still be picked up? Then I would give it a go.
Yes, I don't think anybody is actively working on this, so if you want to give it a shot I'm happy to support you where necessary :slightly_smiling_face:
As it seems that @Maiklins didn't found the time to take over, I would be happy to give it a try. Would it be ok for you @codecholeric?
Didn't got any response so I assume no one is working at this. So I've created #1300
@mathze I did not find the time to start on that one. So go ahead. :)
Note: My PR only allows the plain use as meta annotation. Atm. it does not respect merging nor inheritance from super classes. Imo support for merging and inheritance should be pulled out in a separate feature request, as it requires a quite more elaborated logic, which requires further discussion, shouldn't it?