我编写了我的第一个ArchUnit测试:
import static com.tngtech.archunit.library.dependencies.SlicesRuleDefinition.*;
// more non-static imports
@RunWith(ArchUnitRunner.class)
@AnalyzeClasses(packages = "my.domain.project")
public class PackageStructureTests {
@ArchTest public static final ArchRule NO_
在Controller- service -Datalayer体系结构中,我正在寻找一种方法来验证我的控制器方法是否完全执行了对服务层的一个调用,如下所示:
@DeleteMapping(value = "/{id}")
public ResponseEntity<String> deleteBlubber(@PathVariable("id") long blubberId) {
service.deleteBlubber(blubberId);
return new ResponseEntity<>("ok
如何使用ArchUnit检查所有.*DTO类都应具有默认构造函数。
classes().that()
.haveNameMatching(".*DTO")
.should()
.haveOnlyPrivateConstructors();// instead of this something like 'haveDefaultConstructor'
有没有检查haveDefaultConstructor()的方法?我在文档里找不到它
当您想要测试默认构造函数时,我认为这是非常常见的情况。
耽误您时间,实在对不起, 我一直在尝试使用Archunit,但我无法理解这个问题: ComponentIntersectionException: Class
com.yyy.xxx.common.configurations.properties.SomeClass may not be contained in more
than one component, but is contained in [Common, Configuration] 我有一个相当标准的工厂图;虽然我不想分享它,但可能有一些ArchUnit的细微差别,我遗漏了。我的问题是,具体地说,在高层次上,我肯定做错
我注意到使用标准ArchConditions以下列格式显示消息:
Class <full_class_path> does not <some_rule> in (<class_link>)
但是,对于将冲突消息添加到事件的自定义条件,情况并非如此,例如:
events.add(SimpleConditionEvent.violated(item, item.getName() + " some message"));
这样,就不会自动将违反类的链接附加到消息中。我想知道第一个论点(correspondingObject)实际上是用来做什么的
在ArchUnit中为分层架构创建规则时,我不清楚如何排除单个类(Main)。The base example不包括源和目标。 ..。但我不明白它是如何转化为我的需求的。我只想让Main被忽略。为什么?因为Main引用了所有的层,因为它注入了所有的依赖项。 The original code is in my GitHub along with the failing test.(该项目是一个虚拟项目,因此它的运行很简单;只需克隆它,运行测试,然后看到一个失败)。
是否有可能从ArchUnit-test中的分层测试条件中排除特定的类?
我有如下定义的包A、B、C、D:
<root>
+- A <-- contains a factory class referring to B, C and D.
+-B
+-C
+-D
包A包含由包B、C和D中的类使用和扩展的实用程序和基类。因此,规则应该是A中的类不能引用扩展包中的任何内容,除非A中有一个工厂类,它引用B、C、D中的一堆叶类。因此,需要将工厂类排除在该测试之外。
ArchRule rule = Architectures.layeredArchitectu
ArchUnit 0.14.1没有检测用作泛型字段参数的类型的循环依赖关系。这是ArchUnit中的限制还是我做错了什么?例如:
package com.test.a;
import com.test.b.B;
public class A {
protected B b;
}
package com.test.b;
import java.util.Optional;
import com.test.a.A;
public class B {
protected Optional<A> a; // not detected by archunit
//
我想测试所有Hibernate关联注释(@ManyToOne、@OneToMany、@OneToOne、@ManyToMany)是否都在使用fetch = FetchType.LAZY。这就是工作原理:
private static final Set<Class<? extends Annotation>> associations =
Set.of(ManyToOne.class, OneToMany.class, OneToOne.class, ManyToMany.class);
@ArchTest
public static final A