Code Coverage with Jenkins [closed]
Asked Answered
L

1

9

I am being asked to use Jenkins to test code coverage for a Java Project. The issue is I have never used Jenkins and have scarcely little experience with actual code coverage. I have been searching a bit and I have come across JaCoCo and Cobertura as plugs. The issue is everything talking about them is above my head at this point. My question is this, as I understand it Jenkins and JaCoCo/Cobertura are used to run tests(Junit?), and report on how well the handle my code, but where do they get the test? Obviously I should make them, but what kind of files are these(again Junit?) and how do the tools get them?

If you are feeling generous, are there any good introduction level tutorials for these tools?

Leucoplast answered 15/6, 2013 at 0:37 Comment(0)
B
1

Maybe try looking in this direction:

  • May your project be maven project
  • Use Jenkins (you already do)
  • Use Sonar

Sonar:

There are lot of tutorials how to use Jenkins+Sonar so I guess you will not have much trouble. Sonar is really powerful tool, one of the best I've seen so far. And there is a plugin for Jenkins (but it can be avoided with certain profile in your maven project's pom.xml file).

Baccy answered 15/6, 2013 at 1:31 Comment(7)
What is maven? and what is Sonar?Leucoplast
Google maven. For Sonar I gave you the links. Its a tool that will give you all sorts of data on your code, find bugs, compute test coverage, calculate the beauty of your code, etc...Baccy
OK that sounds good and all and that you for that, but that doesn't entirely answer my question. How do they get the test? I imagine I write something like function testCode() {assertTrue(func(x), y)}, as part of a Java file, but how does Sonar know that, that is a Junit test or any sort of test?Leucoplast
JUnit tests will do that for you. If that fails on assertation jenkins WILL KNOW that (and you dont have to do anything there). Jenkins will run JUnit tests with appropriate command and forward those results to sonar. In my example, Jenkins will invoke a certain maven command, and the command will invoke a certain profile from project's main pom.xml file that is used for testing. Its not easy and you will need hours of setting it, but once you do it, you won't have to do it again.Baccy
Any chance you know of a tutorial that runs through the whole process, from writing a JUnit to the coverage report from Jenkins?Leucoplast
There isn't any that I know of. But, if your project is mavenized, in Jenkins you run your tests with Build > Invoke top-level Maven targets > "clean test-compile org.codehaus.mojo:sonar-maven-plugin:2.0:sonar -Psonar". In your pom.xml you should have this profile: pastebin.com/nt8rfi09Baccy
Too bad Sonar is at sourceforge. I won't touch that website with a ten-foot pole, let alone download anything from it.Whiffle

© 2022 - 2024 — McMap. All rights reserved.