admin管理员组文章数量:1122832
I have a test that looks like this:
@Test
void postUploadShouldReturnOk() throws Exception {
String body = prepareCorrectBody(true);
myTestUtils.performRequestAndAssertStatus(body, status().isOk());
}
I have a whole bunch of these tests in different test classes that all follow this pattern, with different bodies and expected statuses. That's why I extracted the performRequestAndAssertStatus
to a utility class to avoid repetition. However, ever since I did that, SonarQube has marked this as an issue, saying "Tests should include assertions java:S2699"
Now, I've read the documentation for that rule, which can be found here: ;rule_key=java%3AS2699
According to that documentation, it should be possible to parameterize the rule so that it recognizes my custom assertion:
Furthermore, as new or custom assertion frameworks may be used, the rule can be parametrized to define specific methods that will also be considered as assertions. No issue will be raised when such methods are found in test cases. The parameter value should have the following format <FullyQualifiedClassName>#<MethodName>, where MethodName can end with the wildcard character. For constructors, the pattern should be <FullyQualifiedClassName>#<init>.
Example: company.CompareToTester#compare*,company.CustomAssert#customAssertMethod,company.CheckVerifier#.
Parameters
customAssertionMethods
Comma-separated list of fully qualified method symbols that should be considered as assertion methods. The wildcard character can be used at the end of the method name.
I have now tries to implement this by adding it to the existing and working sonar properties in my build.gradle
like this:
sonar {
properties {
property "sonar.gradle.skipCompile", "true"
property "sonar.projectKey", "my-service_12345678-1234-1234-1234-123412341234"
property "sonar.projectName", "My-Service"
property "sonar.coverage.exclusions", "**/MatomoClientImpl.java, **/ConverterClientImpl.java,"
property "sonar.java.customAssertionMethods", "my_service.MyTestUtils#performRequestAndAssertStatus"
}
}
However, that didn't work. I've tried all variations that I could think of too, but none of them worked.
Does anyone have any idea of how to get this to work? According to the documentation, it should be possible, right?
本文标签:
版权声明:本文标题:SonarQube & Java ~ How to parameterize "Tests should include assertions" rule to recognize custom asse 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736303766a1931998.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论