jUnit: How to determine level of code coverage?

2019-03-11 15:39发布

问题:

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.

回答1:

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



回答2:

This presentation points to several tools you can use for the purpose.

  • Cenqua Clover $250-$2500 payware http://www.cenqua.com/clover/

  • Cobertura (GPL): http://cobertura.sourceforge.net/

  • Coverlipse Eclipse plug-in: http://coverlipse.sourceforge.net/index.php

  • Jester: http://jester.sourceforge.net/



回答3:

I would suggest to go for Cobertura for code coverage. It gives detailed information and can give you line by line coverage as well as branch coverage.