How does the Jenkins Cobertura plugin operate to enable source code viewing?
Asked Answered
G

1

5

I'm trying to get a build in Jenkins to show a coverage report of a Java unit test run. I can get the report at the high level showing that coverage has occurred at the class and method level, but part of the report where I can view the source code isn't working.

Gavette answered 14/5, 2014 at 5:13 Comment(0)
G
7

The inputs to the plugin are:

  • a coverage report in XML
  • source code

To use the plug in to create a coverage report:

  1. Install Cobertura into Jenkins.
  2. Create a Jenkins job with a post build to generate Cobertura report. In this step you tell it where in the Jenkins workspace to load the coverage report (often named coverage.xml).

Before you run the Jenkins job The coverage report is created in some way (often by a build script of some kind). The report is often named coverage.xml by most people's build scripts and is placed in the Jenkin's job's workspace.

When running the Jenkins job

When the Jenkins job runs, the Cobertura plugin will read the coverage.xml and use the element to locate the source code. The plugin copies the source code into a cache located at: <Jenkins home>/jobs/<Jenkins job name>/<Cobertura>.

After running the Jenkins job

Read the coverage report by navigating to the Jenkins job that built it. If copying of the source files was successful during running the Jenkins job, you can drill down to the source code and see what lines were covered by the test run. If you can't see the source code level code coverage:

  1. Check the cobertura cache to see if the code is there.
  2. Check the permissions on the cache to see if the Jenkins server process owns that directory and has read, write, execute permission on that directory.
  3. Check the cobertura.xml file and select a element and examine it's "filename" attribute and see if it's path will work as a relative path from the root of the Cobertura cache.

If the cache has old information, delete everything in the cache directory, and re-run the Jenkins job.

Gavette answered 14/5, 2014 at 5:13 Comment(3)
I am only interested in converting a cobertura.xml report to a html report. I have been looking at CoberturaPublisher.java and ran the lines: SourceCodePainter painter = new SourceCodePainter(paintedSourcesPath, sourcePaths, result.getPaintedSources(), listener, getSourceEncoding()); moduleRoot.act(painter); Unfortunately, it does not generate the report. Do you know what part of the code is used generate the report?Thrombosis
Rather than write Java code, how about using style sheets to convert the .xml report into something the browser can understand? I'd start with a working .html report which uses the same .xml report. I'm hazy where to start outside of using google or looking for .html sample reports that come with Cobertura.Gavette
Or find a front end developer friend who's versed in CSS (cascade style sheets.) :-)Gavette

© 2022 - 2024 — McMap. All rights reserved.