Questions tagged [code-coverage]

"Code coverage" (synonym: test coverage) is a measure of the amount of application source code that has been exercised, usually by some testing regime, often by unit testing.

Code coverage is a measure of the amount of application source code that has been exercised, usually by some testing regime, often by unit testing. There are two key questions: given an exercise regime, how much of the source code is executed (under the assumption that the exercise also shows the program effects to be correct), and, given an exercise regime, how does one increase the coverage amount by modifying the exercise.

Determining the actual coverage is normally accomplished by instrumenting the source code to track when its elements are executed, and then simply running the exercise regime. The instrumented data is collected and often displayed in a report and/or a visual display.

Improving coverage given a specific exercise regime is difficult. One must determine for some block of uncovered code, how to cause that code to be executed, often requiring a complex initialization of the program environment to trigger the code block.

Code coverage is also known as , but see that tag's wiki for an alternate meaning.

5306 questions
703
votes
30 answers

What is a reasonable code coverage % for unit tests (and why)?

If you were to mandate a minimum percentage code-coverage for unit tests, perhaps even as a requirement for committing to a repository, what would it be? Please explain how you arrived at your answer (since if all you did was pick a number, then I…
sanity
  • 35,347
  • 40
  • 135
  • 226
660
votes
10 answers

Clearing coverage highlighting in Eclipse

After running coverage reports in Eclipse (using cobertura or an EMMA plugin), my source code files get highlighted in green, red and yellow depending on which lines of code were covered by tests. How can I clear this highlighting after I'm done?
Charbel
  • 14,187
  • 12
  • 44
  • 66
414
votes
12 answers

What can I use for good quality code coverage for C#/.NET?

I wonder what options there are for .NET (or C# specifically) code coverage, especially in the lower priced segment? I am not looking for recommendations, but for a comparison of products based on facts. I know the following: NCover Seems to be…
Michael Stum
  • 177,530
  • 117
  • 400
  • 535
376
votes
4 answers

Code coverage with Mocha

I am using Mocha for testing my NodeJS application. I am not able to figure out how to use its code coverage feature. I tried googling it but did not find any proper tutorial. Please help.
tusharmath
  • 10,622
  • 12
  • 56
  • 83
349
votes
11 answers

What is code coverage and how do YOU measure it?

What is code coverage and how do YOU measure it? I was asked this question regarding our automating testing code coverage. It seems to be that, outside of automated tools, it is more art than science. Are there any real-world examples of how to use…
Brian G
  • 53,704
  • 58
  • 125
  • 140
205
votes
1 answer

ember-cli-code-coverage mocha showing 0% coverage when there are tests

I'm using ember-cli-code-coverage with ember-cli-mocha. When I run COVERAGE=true ember test I'm getting 0% coverage for statements, functions, and lines. Yet, I have tests that are covering those sections. Any I missing something in my setup? unit…
wwwuser
  • 6,282
  • 8
  • 52
  • 64
200
votes
15 answers

How to measure test coverage in Go

Has anyone succeeded in generating code coverage for Go unit tests? I can't find a tool for that on the web.
Georgi Atsev
  • 2,775
  • 2
  • 16
  • 18
184
votes
16 answers

Filter JaCoCo coverage reports with Gradle

Problem: I have a project with jacoco and I want to be able to filter certain classes and/or packages. Related Documentation: I have read the following documentation: Official jacoco site: http://www.eclemma.org/jacoco/index.html Official jacoco…
Jared Burrows
  • 54,294
  • 25
  • 151
  • 185
163
votes
4 answers

How do I read an Istanbul Coverage Report?

I've always used Jasmine for my unit tests, but recently I started using Istanbul to give me code coverage reports. I mean I get the gist of what they are trying to tell me, but I don't really know what each of these percentages represent (Stmts,…
Scott Sword
  • 4,648
  • 6
  • 32
  • 37
163
votes
13 answers

How to configure multi-module Maven + Sonar + JaCoCo to give merged coverage report?

I've searched up and down the internet for this one. There's lots of half-answers out there, to do with Maven properties such as ${sonar.jacoco.reportPath}, or org.jacoco:jacoco-maven-plugin:prepare-agent or setting maven-surefire-plugin argLine…
Stewart
  • 17,616
  • 8
  • 52
  • 80
162
votes
14 answers

How can I unit test a GUI?

The calculations in my code are well-tested, but because there is so much GUI code, my overall code coverage is lower than I'd like. Are there any guidelines on unit-testing GUI code? Does it even make sense? For example, there are graphs in my app.…
Steve McLeod
  • 51,737
  • 47
  • 128
  • 184
141
votes
7 answers

Clear code coverage information in IntelliJ

I have configured IntelliJ to paint the background of any line that has been executed at runtime to green when running in Coverage mode. At times, I would like to just make all the files in the project revert back to their old and typical background…
devoured elysium
  • 101,373
  • 131
  • 340
  • 557
139
votes
18 answers

How to add test coverage to a private constructor?

This is the code: package com.XXX; public final class Foo { private Foo() { // intentionally empty } public static int bar() { return 1; } } This is the test: package com.XXX; public FooTest { @Test void…
yegor256
  • 102,010
  • 123
  • 446
  • 597
122
votes
5 answers

Is it possible exclude test directories from coverage.py reports?

I'm kind of a rookie with python unit testing, and particularly coverage.py. Is it desirable to have coverage reports include the coverage of your actual test files? Here's a screenshot of my HTML report as an example. You can see that the report…
Kyle Fox
  • 3,133
  • 4
  • 23
  • 26
118
votes
12 answers

What code analysis tools do you use for your Java projects?

What code analysis tools do you use on your Java projects? I am interested in all kinds static code analysis tools (FindBugs, PMD, and any others) code coverage tools (Cobertura, Emma, and any others) any other instrumentation-based tools anything…
Joshua McKinnon
  • 24,489
  • 11
  • 57
  • 63
1
2 3
99 100