Sonarqube test case rule does not take @Test annot

2019-08-12 03:42发布

问题:

Sonarqube generates issues as

TestCases should contain tests

regarding that test classes does not have any tests inside but there are methods marked with @Test annotation and classes annotated with @RunWith(SpringJunit4ClassRunner.class).

I have no problem running TestSuites and importing unit test and coverage reports into sonarqube. I checked sonarqube source code and it should find annotations but unfortunately it does not. Rule id for the mentioned issue is S2187.

Is there a configuration for this rule to find annotated methods or is a known issue?

Edit - config:

sonar.projectKey=x
sonar.projectName=x
sonar.projectVersion=1.0 
sonar.modules=a,b,c
a.sonar.projectBaseDir=modules/a
b.sonar.projectBaseDir=modules/b
c.sonar.projectBaseDir=modules/c
sonar.sources=src
sonar.tests=test
sonar.java.binaries=../**/classes/production,../**/classes/test
sonar.java.libraries=../../libraries/repository
sonar.junit.reportsPath=junit/
sonar.java.coveragePlugin=jacoco
sonar.jacoco.reporthPath=coverage/jacoco.exec
sonar.language=java
sonar.sourceEncoding=UTF-8

回答1:

Issue has been fixed by correctly setting sonar.java.test.libraries/binaries attributes as answered in https://stackoverflow.com/a/32197912/343806. They were not not in the runner configuration and after adding raised issues in sonarqube results marked as fixed.