3

I'm running my webApp using Jetty with my instrumented classes. After the shutdown of Jetty i'm taking the generated .set file and creating a cobertura report using the command line tool.

I always get 100% coverage results on any class. It seems that Cobertura takes into account only the lines that were executed during testing, and doesn't get the full class data.

I've tried to add source files to the reports - no help. I also tried to take the .ser file created after the instrumentation and merge it with .ser file created after Jetty shutdown (it is actually the same file, but before running Jetty I backed-up the .ser which was created after instrumentation) - no help here either.

Can someone please help??

Thanks

Ben Bracha
  • 1,377
  • 2
  • 15
  • 28

2 Answers2

2

As explained at http://cobertura.sourceforge.net/faq.html, in the answer to the question "When I generate coverage reports, why do they always show 100% coverage everywhere?",

"Cobertura is probably using the wrong .ser file when generating the reports. When you instrument your classes, Cobertura generates a .ser file containing basic information about each class. As your tests run, Cobertura adds additional information to this same data file. If the instrumented classes can not find the data file when running then they will create a new one. It is important that you use the same cobertura.ser file when instrumenting, running, and generating reports."

In my case, I experienced this issue when instrumented classes were in one .ser and during execution I was generating another .ser. Generating the HTML report "just" from the second .ser shown the problem mentioned in the question. Merging the two datafiles (.ser), and regenerating the report, solved the issue.

Refer to http://cobertura.sourceforge.net/commandlinereference.html for "Merging Datafiles" information.

2

100% coverage is a clear indicator, that the sources are missing for the report. You should check your configuration for creating the report.

Make sure that:

  • you give the right folder
  • the source folder is structured like the packages, and not just all classes in one dir
oers
  • 18,436
  • 13
  • 66
  • 75
  • Thanks - I corrected the source folder path (it was wrong) and now I can see source code in the reports! But still coverage is 100% everywhere (and you see on source code that it actually is not) – Ben Bracha Nov 08 '11 at 14:16
  • 2
    Well - found the problem! Because we did the all process manually, it seems we accidentally instrumented the already-instrumented classes.. I guess that got Cobertura confused (source code did not match anymore) and generate wrong reports.. Thanks! – Ben Bracha Nov 08 '11 at 14:52