Best practice integrating Spock with Jenkins, Sonar [closed]
Asked Answered
P

2

7

We decided to give Spock a try as a testing framework for our java based EE application. Currently we have a CI infrastructure deployed based on jenkins + maven + jacoco.

Q: the question is what's the best way to integrated spock with all this? Any recommendations, best practices?

Premillennial answered 8/5, 2013 at 11:6 Comment(0)
M
4

Given your tool chain, the only thing that's different compared to Java/JUnit is to make Groovy (test) compilation work in Maven (see the spock-example project). Other than that, you shouldn't have to do anything special, as Spock is just a custom JUnit runner that's activated automatically. You'll get the same reports etc. You can even have Spock and JUnit tests in the same source directory and run them together.

Mandal answered 8/5, 2013 at 15:44 Comment(1)
Per my comment on Aaron McDowell's answer, you should also install the Groovy plugin on the SonarQube server so that Sonar is aware of your Groovy test files.Covet
R
2

Actually you may have trouble integrating with Sonar. The Sonar Surefire sensor will successfully find your surefire reports; however, the sensor attempts to link to the test source for publishing to Sonar. When it does this, it assumes a file extension of .java. So you will see output in your build that looks like this:

[INFO] [13:00:34.734] Sensor SurefireSensor...
[INFO] [13:00:34.735] parsing /home/amcdowel/accurev/projectFoo/target/surefire-reports
[WARN] [13:00:34.747] Resource not found: com.abc.monitor.app.model.MonitorTest

The code coverage generated by your Spock tests will successfully be reported in your Sonar dashboard, but the number of unit tests and success/error counts will not be included.

Riverside answered 11/3, 2015 at 20:15 Comment(1)
It looks like this is not true if you install the Groovy plugin in the SonarQube server. I was able to get my project's Groovy (Spock) tests to show up by installing the plugin, updating the sonar.tests property to include my Groovy source directory, and rerunning the Sonar Maven task. <properties><sonar.tests>src/test/java,src/test/groovy</sonar.tests></properties>Covet

© 2022 - 2024 — McMap. All rights reserved.