Cobertura, coverage over multiple jar-files - java

Is there a way to get Cobertura to gather test-coverage over several .jar-files. The problem I have is that after a refactoring of classes that where covered, being in the same .jar, are no longer being reported as covered (since they now are in a separate .jar).
So, the question, for a ear-project, containing several source-projects (.jar), is there a way to get the actual coverage for the ear-project instead of a sum of of .jar-coverages.
Basically, the tests reflects behaviour, not code-structure. Since we only changed structure, the behaviour isn't changed. Therefore the tests should not need to change and since the tests are not changed then the coverage should not change.

You've 2 good options:
1) Have your cobertura maven plugin in a single (parent) pom and set the aggregate property to true, which should overlay your cobertura reports on top of each other. See this blog post as an example.
2) If you only care about the report, use a report aggregating tool such as Sonar to not only give you aggregated reports across the project, but a whole host of extra metrics and useful info.

I have red that if you organized your project in a Maven multi-module project (one module for each jar) you should be able to merge the cobertura reports in one report, but I have never tryed what written at that page.

Related

How to exclude test classes form Coverage Analysis using Jacoco

I have some test to check my code. I have generated my report in sonarcloud but I have a problem: The coverage percentage takes into account also the test classes, that are obviously uncovered by other test. Is there any option just to take into account all the classes but the test ones??
First of all i would not adapt Jacoco, but you can exclude files from coverage report within sonarqube/sonarcloud with the sonar.coverage.exclusions property, where you can eg. specify a pattern like **/*Test.java to exlude all java files ending with Test.
Additionally you could also set this up within the UI, represented on the following screenshot:
Sidenote: i would inspect the sonar configuration, for me it looks like that test code is provided as normal sources to sonar. This would create such an topic, but normally sonar has an own property to configure test code. see analysis parameters documentation for further details or if you use gradle or maven plugins, check the respective documentation on how to organize the source code.

SonarQube not displaying classes under coverage

I have been working on setting up code coverage metric on SonarQube for a Java project using jacoco plugin.
The project builds successfully (using ant), jacocoreport.xml and jacocoreport.csv files get generated with the right information on covered/missed counter values for the covered/uncovered classes and methods. However, the dashboard on SonarQube reports "0.0%" as the metric value even when there is a single class file which has a covered method, and it provides absolutely NO information on "what classes have what coverage". In fact, upon clicking "0.0%" coverage link, I do not see (under "List" or "Tree") the particular folder which contains the classes I have written jUnit Tests for.
I checked with another developer from a different project who has worked on this before. She tells me that her project has around 2000 Unit Test methods and her jacoco.exec file size is 6MB. My project, on the other hand, has 1 to 2 Unit Test method(s) and the file-size is 6KB. Not sure if the jacoco.exec is generated properly.
How do I make sure the dashboard gives information on the covered/uncovered classes? Do you think it's not reporting because the the project has just one covered class file. I don't think this should be a problem. But I am not sure what's wrong.
NOTE: While running the Sonar Scanner locally, I noticed warnings that said some of the class files couldn't be accessed through the ClassLoader. This issue didn't get resolved even after me adding Sonar.Libraries and Sonar.Binaries properties (please ignore uppercase in this text).

How to exclude files from IntelliJ code coverage by name pattern?

I'm using IntelliJ 2017.3 to measure the code coverage of my tests. The code base contains some more or less dumb classes that should be excluded from this measurement. I want to exclude all classes which contain Factory as part of their name (example: AverageOperatorFactoy) and tried it with the patterns *Factory and .*Factory (although it seems like regex are not used here), but IntelliJ still shows factories in the coverage report.
How can I exclude classes with a name pattern?
I have the same issue using a very basic pattern like
com.example.myproject.somecode.*
While including works as expected, excluding has no effect at all.
This is seems to be a known issue in IntelliJ. See Code coverage Report includes excluded packages
If you don't have too many packages in your project, you could still do the opposite and include only those packages you want using several active include patterns together.
Alternatively you can use the now free IntelliJ plugin Open Clover which offers much better coverage configuration and result browsing than IntelliJ ships with.

Configure Sonar 6.2 code coverage on a Maven project

I have pretty standard Maven multi-modules project (with JUnit, Arquillian and Selenium tests). I have Sonar 6.2 installed on a server. And on my project on Sonar the Code Coverage metric indicates 0.0%. But I know it's wrong as I do have some test coverage.
I found this Generic Test Data documentation page that explains that since 6.2 Sonar is supporting code coverage out of the box and that I have to pass a comma-delimited list of report paths to a parameter sonar.coverageReportPaths (I guess provided either in my pom or in command line).
I'm fine with that. But I cannot find out an example on how to setup this for a pretty classical Java project. What kind of file do I need to give in the list ? The relative paths to each of my Surefire/Failsafe reports ? Do I need to generate Jacoco reports in addition ? Can I give a "generic" path like report.xml if all of my reports have the same name ?
For standard Java project is it probably the easiest to use JaCoCo to generate coverage data and then feed it to SonarJava (SonarQube's plugin to analyze Java code). You can find documentation here
https://docs.sonarqube.org/display/PLUG/Code+Coverage+by+Unit+Tests+for+Java+Project
You might find mentions of separation between unit tests and integration tests, this has been deprecated and now there is only single kind of coverage.
Don't hesitate to reach out to mailing list or ask question if something is not clear, we are in the process of improving this documentation.

Is it possible to run incremental/automated JUnit testing in Eclipse?

Eclipse support incremental compiling. If I save a source file then it will compile the modified files.
Is it possible after such incremental compile also to run the JUnit tests of the same package and show the fail in the error view. Then I can see the JUnit test failing and compiling errors in the same view without extra action. Are there any plugins that can do it?
You have to look at these plugins:
JUnit Max: Not free, developed by Kent Benk (one of the men behind the TDD practice);
MoreUnit: Free, but essentially dedicated to help you write the tests;
Infinitest: Now free, this plugin is dedicated to run the tests related to the files you have just modified.
So regarding your needs, I suggest that you install MoreUnit and Infinitest plugins.
Use ExternalToolBuilder.
It can be triggered by source modify.
There’s Eclipse customized feature(integrate external tool builder) which may meet your need. But it needs extra effort to write the scripts I never used. Automatic test cases is not a convenient way, at least single click to see green bar in Eclipse is enough for me:)
You can run all tests in a project using Alt+Shift+X,T. I think that making it any more automated than this could take a serious performance toll. Incremental compilation is compiling at most 1 file at a time, but you're talking about running potentially hundreds of tests.

Categories

Resources