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
104
votes
12 answers

how to use jacoco.exec report

I generated a code coverage report from jacoco, which is jacoco.exec. But I don't know how to use it ... The way I generated it is through command line: java -javaagent:/path/to/jacocoagent.jar=include=some.package.*,output=file…
wlhee
  • 2,334
  • 4
  • 18
  • 19
98
votes
11 answers

Mocking Java enum to add a value to test fail case

I have an enum switch more or less like this: public static enum MyEnum {A, B} public int foo(MyEnum value) { switch(value) { case(A): return calculateSomething(); case(B): return calculateSomethingElse(); } throw new…
fortran
  • 74,053
  • 25
  • 135
  • 175
98
votes
7 answers

Free NCrunch alternative

Since NCrunch has left the free market, I was looking for a similar tool for code coverage marking, and continous testing like NCrunch edit: I'm using VS2012 update: I've been using ContinuousTest for a while now, it's OK, but I think it lacks…
Pacane
  • 20,273
  • 18
  • 60
  • 97
89
votes
5 answers

Perl build, unit testing, code coverage: A complete working example

Most Stackoverflow answers that I have found in regards to the Perl build process and unit testing and code coverage simply point me to CPAN for the documentation there. There's absolutely nothing wrong with pointing to CPAN modules because that's…
89
votes
11 answers

How can the code coverage data from Flutter tests be displayed?

I'm working on a Flutter app using Android Studio as my IDE. I'm attempting to write tests and check the code coverage but I can't work out how to view the data in the IDE or any other application. By running flutter test --coverage, a coverage…
86
votes
3 answers

What is a branch in code coverage for JavaScript unit testing

I use Istanbul for code coverage of unit tests in an AngularJS project. There are 4 types of coverage and they are statement branch function line Statement, function and line are alright but i don't understand what "branch" is. What is branch?
Evren Kutar
  • 1,173
  • 1
  • 9
  • 12
82
votes
9 answers

Laravel 5: PHPUnit and no code coverage driver available

I would like to use PHPUnit to create code coverage reports. I have tried a lot of installation setups found on the web. But nothing seems to work out. I use the latest version of Laravel 5 (>5.2) and PHPUnit v. 5.0.10. Further, I use MAMP on Mac OS…
LaDude
  • 1,383
  • 1
  • 11
  • 27
80
votes
10 answers

How to get code coverage using Android Studio?

I am developing apps using Android Studio. I was able to run the test code. But, I do not know how to get code coverage in android studio. I have already seen the following links. Android Gradle Code Coverage But I can't wait for update to v0.6…
h.usune
  • 933
  • 1
  • 7
  • 9
75
votes
12 answers

Find unused code in a Rails app

How do I find what code is and isn't being run in production ? The app is well-tested, but there's a lot of tests that test unused code. Hence they get coverage when running tests... I'd like to refactor and clean up this mess, it keeps wasting my…
oma
  • 38,642
  • 11
  • 71
  • 99
74
votes
6 answers

How to ignore lines for code coverage in Jest

In Jest, is there any way to ignore code for test coverage? I tried using /* istanbul ignore next */ But it doesn't seem to work.
Nahush Farkande
  • 5,290
  • 3
  • 25
  • 35
72
votes
6 answers

How would I add an annotation to exclude a method from a jacoco code coverage report?

I have some code in Java that I want to exclude from code coverage. How would I do this? I want to be able to add an annotation. Is there a way to configure or extend jacoco (as used in gradle) to use this? Example: public class Something { …
Don Rhummy
  • 24,730
  • 42
  • 175
  • 330
69
votes
5 answers

Code coverage with nUnit?

Is there a way to see the code coverage when using nUnit? I know there's such a feature in Visual Studio, but can you use it with nUnit or only with the built-in vs unit tests?
Lieven Cardoen
  • 25,140
  • 52
  • 153
  • 244
66
votes
4 answers

preventing python coverage from including virtual environment site packages

I am new to coverage and ran into a strange problem. My coverage is taking my virtual environment site packages into account. Here is the output of the coverage run: coverage run…
66
votes
5 answers

How do code coverage tools work?

How do code coverage tools like NCover know what parts of the code were executed and what parts were not?
Hannoun Yassir
  • 20,583
  • 23
  • 77
  • 112
65
votes
3 answers

how to get which statements are missed in python test coverage

I am new to python, I have written test cases for my class , I am using python -m pytest --cov=azuread_api to get code coverage. I am getting coverage on the console as How do I get which lines are missed by test for e.g in aadadapter.py…
Planet-Zoom
  • 1,005
  • 2
  • 9
  • 20