Questions tagged [cobertura]

Cobertura is a free and open-source Java tool based on jcoverage that calculates the percentage of code and branches covered by tests.

Cobertura is a free and open-source Java tool (commonly called a code coverage tool) based on jcoverage that calculates the percentage of code and branches covered by tests.

Cobertura does this by instrumenting the compiled bytecode. It can be run from the command line, via an Ant task, via a Maven plugin, or via the eCobertura Eclipse plugin. Builds can be made to fail if the code coverage reported by Cobertura does not meet a user-set threshold value. XML and HTML reports can be generated as output.

649 questions
7
votes
1 answer

Cobertura showing wrong line coverage

I see a strange cobertura report. It says that line number 89 (see screenshot) siteMapItems = getItemFromPage(navParentPage, 0); is executed once, but the method called on this line (getItemFromPage) shows no line coverage. I have also added logs…
Ankit
  • 3,083
  • 7
  • 35
  • 59
7
votes
3 answers

Cobertura Maven Plugin fails with "The command line is too long" on Windows

When I run cobertura-maven-plugin on Windows 8.1 with lengthy configuration (used to prohibit any coverage drop in the project) cobertura:check goal fails with error The command line is too long. The problem is probably connected to Command prompt…
Michal Kordas
  • 10,475
  • 7
  • 58
  • 103
7
votes
0 answers

Cobertura: How to interpret the colors

I'm using cobertura and I am confused about the meaning assigned to the colors in the report. I checked the cobertura website, as well as their FAQ and github page, and searched old stack overflow questions, but I could not find an explanation of…
msknapp
  • 1,595
  • 7
  • 22
  • 39
7
votes
2 answers

Static class initialization not performed when running JUnit test

I have a java class with some static fields: private static final PDMapCacheDAO REST_CACHE_DAO = new PDMapCacheDAOImpl( Constants.REST_CACHE_NAME ); private static final PDMapCacheDAO HOLIDAYS_CACHE_DAO = new PDMapCacheDAOImpl(…
user2031818
  • 71
  • 1
  • 2
6
votes
5 answers

Can I automatically execute JUnit testcases once with all logging enabled and once with all logging disabled?

I've found a solution, see my own answer below. Does anyone have a more elegant one? I want to do this to increase code-coverage and find subtle bugs. Assume the following class to be tested: public class Foo { private final Logger logger =…
Huxi
  • 4,242
  • 3
  • 33
  • 31
6
votes
3 answers

Code coverage / branch coverage recommended values

I'm using Cobertura to calculate code/branch coverage for a Java project with JUnit test cases. I know 100% coverage does not tell how good the code is, but at the moment it's 6%. Branch coverage is 1%. My intuition says branch coverage is probably…
Matthias van der Vlies
  • 3,834
  • 3
  • 24
  • 28
6
votes
2 answers

How to specify a global system property for java applications?

I'm trying to integrate Cobertura into our test environment to be able to capture code coverage information. The tests are run from ant scripts using ANT junit tasks, and there are more than 50 ant script files (build.xml) with one or more junit…
srkavin
  • 1,152
  • 7
  • 17
6
votes
2 answers

Cobertura coverage for integration tests in Maven

I can invoke mvn cobertura:cobertura to instrument, run unit tests (using surefire), and generate reports. I can invoke mvn verify to run unit tests and integration tests (using the failsafe Maven plugin). But how do I call Maven to instrument, run…
Michael Piefel
  • 18,660
  • 9
  • 81
  • 112
6
votes
3 answers

IllegalAccessError:class cannot access its superinterface

I have class Assembly implementing IAssembly. I see following error when starting the application Caused by: java.lang.IllegalAccessError: class cannot access its superinterface at…
Jayan
  • 18,003
  • 15
  • 89
  • 143
6
votes
2 answers

Gitlab CI not showing Cobertura code coverage visualization

I am trying to show test coverage visualization in Gitlab for our monorepo as described here Test Coverage Visualization We are using a self-managed gitlab runner with the docker+machine executor hosted on AWS EC2 instances. We are using Gitlab…
Benjamin
  • 526
  • 6
  • 16
6
votes
1 answer

How do I create a coverlet coverage report on Azure DevOps Pipeline with a ".Net FrameWork 4.7" project?

I'm currently trying to create a Coverlet coverage report with a pipeline on Azure DevOps. But, since my project is a ".Net FrameWork 4.7" project, I can't create a coverage report using "DotNetCoreCLI@2" task like a ".Net Core" project. There's my…
6
votes
4 answers

Cobertura coverage and the assert keyword

My line coverage for unit tests measured by Cobertura is suffering, because I have assert statements which are not covered in tests. Should I be testing assertions, and is there any way to get Cobertura to ignore them so they do not affect my test…
Armand
  • 23,463
  • 20
  • 90
  • 119
6
votes
1 answer

What is the color and number beside the line number in cobertura report

I used mvn cobertura:cobertura to generate this cobertura JUnit test coverage report. Can anyone explain to me what do the numbers beside the line number mean? Thank you.
Tech Noob
  • 510
  • 1
  • 9
  • 33
6
votes
3 answers

SonarQube: Coverage on New Code never calculated

I have set up SonarQube, Maven and Cobertura to upload unit test coverage at every build run. I want to use the differential views to get coverage for the delta (new code only). The coverage itself is successfully uploaded, and I can see the delta…
MisterStrickland
  • 947
  • 1
  • 15
  • 35
6
votes
1 answer

How to test a Method with a Boolean return type in Java with JUnit

I am writing a JUnit test case for a method to get a Line and Branch coverage. Method under test invokes another method of type Boolean and I am unable to cover that part because on the Cobertura report the following line shows red. if…
user5192032