• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How do you integrate Spock's test with Sonar?

 
Greenhorn
Posts: 2
Netbeans IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
In my job we usually check the Sonar code metrics, especially the code coverage. We often doing this task using maven sonar plugin. However, I don't know if it is possible with Spock in the same way or if exist another way.
Thanks a lot
 
Author
Posts: 16
5
Spring VI Editor Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Omar

As explained in my "Sonar vs JUnit" post, Spock works beautifully with Sonar as it uses internally the JUnit runner. This means that Sonar and Maven can run Spock tests and "see" them as JUnit tests.
Code coverage works like JUnit.

An example is shown in chapter 7 of the book.
The code uses the Jacoco plugin, Maven and nothing else. There is no Spock-specific configuration that you need in Sonar.

Here is the pom file
https://github.com/kkapelon/java-testing-with-spock/blob/master/chapter7/spring-standalone-swing/pom.xml

And here is the screenshot from Sonar from this example (attached on this post)

Kostis






sonar.png
[Thumbnail for sonar.png]
 
Omar Fernandez
Greenhorn
Posts: 2
Netbeans IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Kostis and your book is awesome
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@ Kostis : I know this is old post nonetheless trying out my luck.

I tried to run mvn sonar:sonar on the project https://github.com/kkapelon/java-testing-with-spock/tree/master/chapter7/spring-standalone-swing

I do see the coverage reported  but the groovy tests are totally missing
Coverage :44.1%

my project has got spock tests and java tests  and only Java test are being reported on the dashboard

Coverage :50.2 % Coverage 9 Unit Tests

I have attached screen shots would you be able to help me out?
Screen-Shot-2017-01-26-at-11.04.22-PM.png
[Thumbnail for Screen-Shot-2017-01-26-at-11.04.22-PM.png]
Screen-Shot-2017-01-26-at-11.04.37-PM.png
[Thumbnail for Screen-Shot-2017-01-26-at-11.04.37-PM.png]
 
Kostis Kapelonis
Author
Posts: 16
5
Spring VI Editor Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Harry

You are correct. I verified this issue. However when I wrote the book I used an older version of Sonar so things might have changed since then.

I have seen that you posted the same question in stack overflow. I will post there if I find any solution to this.

http://stackoverflow.com/questions/41886878/integrate-spocks-test-with-sonar

To tell you the truth, Sonar is changing so much between each version that I find it frustrating to keep up. Even their LTS versions are not as stable as they should be.

Kostis
 
Kostis Kapelonis
Author
Posts: 16
5
Spring VI Editor Java
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Harry

I found the solution!

First of all chapter 7 has only Spock tests. I used chapter1 that has both JUnit and Spock tests.

The solution is the following
1)Install the Groovy plugin in Sonar. Login as admin/admin and go to administration->System->update center tab
2)Add the following property in the pom file

If you do this both Spock and JUnit tests are shown correctly!
See attached screenshot


Enjoy!
spock-sonar.png
[Thumbnail for spock-sonar.png]
 
harry devnull
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thank you Kostis I had been hammering my poor little brain with all sort of combinations; but was unable to make it work
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic