Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 297
Hannoun Yassir Avatar asked Jun 16 '10 08:06

Hannoun Yassir


People also ask

How does a test coverage tool work?

Test coverage is defined as a technique which determines whether our test cases are actually covering the application code and how much code is exercised when we run those test cases. If there are 10 requirements and 100 tests created and if 90 tests are executed then test coverage is 90%.

What is the purpose of code coverage tools?

Your code coverage tool will monitor the execution of your test suite and tell you how much of the statements, branches, functions and lines were run as part of your tests.

How is code coverage determined?

To calculate the code coverage percentage, simply use the following formula: Code Coverage Percentage = (Number of lines of code executed by a testing algorithm/Total number of lines of code in a system component) * 100.

How does code coverage tool work in Java?

It requires that you run your tests once with code coverage analysis enables, and then simply counts the number of blocks (that is, scope blocks) covered and compares to the total number of blocks in the project(s) you are testing.


2 Answers

Here's a technical paper on How to Implement test coverage tools for arbitrary languages.

My company builds a family of test coverage tools for Java, C#, C++, PHP, COBOL, PLSQL, ... based on this principle.

like image 127
Ira Baxter Avatar answered Sep 30 '22 15:09

Ira Baxter


Quote straight from the NCover FAQ: NCover reports the percentage of branches in the code that have been taken throughout the course of your automated testing. It achieves this by instrumenting the source code at each branch, and writing the 'hit' points to a file. These 'hit' points are then compared to the total possible points that could have been 'hit'.

like image 35
Hans Olsson Avatar answered Sep 30 '22 17:09

Hans Olsson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!