英文:
Is there a similar option to ImportOption.DoNotIncludeTests on a per test level in ArchUnit
问题
在ArchUnit中,是否可以在每个测试基础上以编程方式从测试包中筛选出类?
这应该基本上与@AnalyzeClasses(packages = "....", importOptions = ImportOption.DoNotIncludeTests.class)在类级别上的行为相同。
背景是我们有一些ArchTests应该针对所有类运行,但也有一些只应该针对不在测试位置的类运行。
也许类似这样的方式?
Architectures.onionArchitecture()
....
.check(classes.that(areNotTests())); ??
英文:
My question is if we can filter out classes from the test packages programmatically on a per test basis in ArchUnit ?
It should be basically the same behaviour that @AnalyzeClasses(packages = "....", importOptions = ImportOption.DoNotIncludeTests.class) does on a class level.
Background is that we have some ArchTests that should run against all classes but also some which only should run against classes that are not in the test location.
Something like that maybe?
Architectures.onionArchitecture()
....
.check(classes.that(areNotTests())); ??
(We can achieve the goal by creating two Classes that hold the ArchUnit tests seperately and only add the ImportOption.DoNotIncludeTests to the one of them. But we would rather have one set of classes to analyze and decide on a per test level. If there is a way to achieve that)
答案1
得分: 1
ImportOption
操作 Location
,但你可以尝试使用以下适配器:
DescribedPredicate<JavaClass> notTests = DescribedPredicate.describe("not tests",
javaClass -> javaClass.getSource()
.map(Source::getUri)
.map(Location::of)
.map(ImportOption.Predefined.DO_NOT_INCLUDE_TESTS::includes)
.orElse(true) // test classes should have a source;
// alternatively, you could probably also use:
// .orElseThrow(IllegalStateException::new)
);
英文:
ImportOption
s operate on Location
s, but you can try to use the following adapter:
DescribedPredicate<JavaClass> notTests = DescribedPredicate.describe("not tests",
javaClass -> javaClass.getSource()
.map(Source::getUri)
.map(Location::of)
.map(ImportOption.Predefined.DO_NOT_INCLUDE_TESTS::includes)
.orElse(true) // test classes should have a source;
// alternatively, you could probably also use:
// .orElseThrow(IllegalStateException::new)
);
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论