Kostis Kapelonis (63) [Avatar] Offline
It has come to my attention via this stackoveflow question that in the recent versions of SonarQube, if a project has both JUnit and Spock tests, only the JUnit ones are shown.


Code coverage is calculated correctly (for both types of tests) and shown accordingly so nothing is broken regarding this aspect. It would be good however to be able to inspect Spock tests as well via the SonarQube interface.

The solution to the problem involves the following two steps:

1. Install the Groovy plugin in Sonar. Login as admin/admin and go to the administration/system/update-center tab

2. Add the following property in the pom file


After the next SonarQube run (mvn sonar:sonar) both types of tests will appear correctly.
(See attached image)


Prajeesh Kumar (2) [Avatar] Offline
Property entries
[ 180 bytes ]
Hi Kostis Kapelonis,

I still face the issue where in I have test written in both JUnit and Spock. The spock tests are written in groovy.

Sonar shows only the Junit Test and doesn't include the groovy Unit Test

I have sonar 6.4 and latest groovy plugin installed in sonar

I am using the gardle 3.5 + sonarqube plugin 2.5

I am attaching the busild script as well as the log file with debug info

Your help is appreciated

Best Regards
Prajeesh Kumar

Kostis Kapelonis (63) [Avatar] Offline
Hello Prajeesh

Sorry for the late reply, but I just came back a vacation trip

I looked at your build log and I see the following:

08:09:12.596 [DEBUG] [org.sonarqube.gradle.SonarQubeTask] 'src/ext/generic/util/GenericUtil.java' indexed with language 'java'

08:09:12.598 [DEBUG] [org.sonarqube.gradle.SonarQubeTask] 'test/groovy/ext/generic/util/GenreicUtilUnitTest.groovy' indexed as test with language 'grvy'

08:09:12.598 [DEBUG] [org.sonarqube.gradle.SonarQubeTask] 'integTest/groovy/ext/generic/util/GenreicUtilIntegTest.groovy' indexed as test with language 'grvy'

08:09:12.598 [DEBUG] [org.sonarqube.gradle.SonarQubeTask] 'test/java/ext/generic/util/MyDemoUnitTest.java' indexed as test with language 'java'

All these files look like JUnit tests. What folder contains your Spock tests?
Prajeesh Kumar (2) [Avatar] Offline

Thanks for the mail reply. All my .groovy files in test and integTest folders are Spock Unit Test only.

Best Regards

Prajeesh Kumar
Kostis Kapelonis (63) [Avatar] Offline
So what do these files contain? The specification classes?

Even though it is not strictly required, it is best if you name you Spock tests as *Spec.groovy and keep the *Test pattern for JUnit tests.

Do your Spock tests run successfully from the command line?