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.
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.
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 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.
I've used EclEmma very successfully to cover JUnit test runs. And its free.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With