Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ensuring code coverage in unit testing?

Tags:

I have noticed that even though I have a lot of doctests in our Python code, when I trace the testing using the methods described here:

traceit

I find that there are certain lines of code that are never executed. I currently sift through the traceit logs to identify blocks of code that are never run, and then try to come up with different test cases to exercise these particular blocks. As you can imagine, this is very time-consuming and I was wondering if we are going about this the wrong way and whether you all have other advice or suggestions to deal with this problem, which I'm sure must be common as software becomes sufficiently complex.

like image 688
reckoner Avatar asked Jul 23 '10 20:07

reckoner


People also ask

How do you test code coverage in unit testing?

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 is code coverage implemented?

Code coverage is a white-box testing technique performed to verify the extent to which the code has been executed. Code coverage tools use static instrumentation in which statements monitoring code execution are inserted at critical junctures in the code.

What are code coverage techniques?

Five Code Coverage methods are 1.) Statement Coverage 2.) Condition Coverage 3) Branch Coverage 4) Toggle Coverage 5) FSM Coverage. Statement coverage involves execution of all the executable statements in the source code at least once. Decision coverage reports the true or false outcomes of each Boolean expression.


1 Answers

coverage.py is a very handy tool. Among other things, it provides branch coverage.

like image 93
Hank Gay Avatar answered Sep 21 '22 03:09

Hank Gay