Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jUnit: How to determine level of code coverage?

How can i determine what percentage of my methods (and code) are covered by jUnit tests? I am assuming there is a more sophisticated way then simply counting ... and 1 and 2 and ..

I specifically wonder how will such counting be handled when single method is covered by 'n' tests.

like image 347
James Raitsev Avatar asked Aug 12 '10 16:08

James Raitsev


People also ask

How do you determine code coverage?

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.

What is JUnit code coverage?

Eclipse can check your code coverage when it runs your JUnit testing class. This means that it can show you what statements were executed in at least one test case and what ones weren't. For an if-statement, it will tell you whether there was a test case for the condition to be false and another for it to be true.

How do you measure unit test coverage?

How to Calculate Test Coverage. Calculating test coverage is actually fairly easy. You can simply take the number of lines that are covered by a test (any kind of test, across your whole testing strategy) and divide by the total number of lines in your application.


1 Answers

I've used EclEmma very successfully to cover JUnit test runs. And its free.

like image 93
quamrana Avatar answered Oct 20 '22 00:10

quamrana