【发布时间】:2018-06-29 16:17:58
【问题描述】:
我将 PMD 用于包含 MockMvc 测试的 Spring Boot 项目。该类强制用户捕获一般Exception。
class MockMvc {
public ResultActions perform(RequestBuilder requestBuilder) throws Exception {}
}
使用会导致 PMD 错误 - SignatureDeclareThrowsException。我想禁止检查所有 @Test 方法。因此我尝试关注Stackoverflow answer,但配置更改无效。
<rule ref="rulesets/java/strictexception.xml/SignatureDeclareThrowsException" >
<properties>
<!-- Ignore @Test methods -->
<property name="violationSuppressXPath" value="
//ClassOrInterfaceBodyDeclaration/Annotation/MarkerAnnotation//Name[@Image='Test']" />
</properties>
</rule>
我怎样才能实现它?
抽象语法树显示了测试方法的以下子树。
> ClassOrInterfaceBodyDeclaration
> Annotation
> MarkerAnnotation
> Name:Test
> MethodDeclaration:(public)
> ResultType:(void)
...
【问题讨论】:
-
也许你可以试试这个方法:stackoverflow.com/questions/47815987可能重复。虽然它很可能会排除整个班级。
标签: java junit abstract-syntax-tree pmd