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.

James Raitsev
  • 92,517
  • 154
  • 335
  • 470

3 Answers3

39

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

quamrana
  • 37,849
  • 12
  • 53
  • 71
  • 4
    Not sure if this is the best answer. I have looked at EclEmma and it appear it is an eclipse plugin. I need to do this in a CI environment and EclEmma is not available as a gradle plugin. – Dimitri Kopriwa Jun 02 '17 at 16:09
  • EclEmma's underlying test library, [JaCoCo](https://www.eclemma.org/jacoco/), is available as a Maven plugin and I think can be used in a CI environment. I'm not sure if a Graddle plugin is available. – Gaurav Nov 09 '18 at 00:04
3

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

Leif Gruenwoldt
  • 13,561
  • 5
  • 60
  • 64
Alex Martelli
  • 854,459
  • 170
  • 1,222
  • 1,395
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.

Leif Gruenwoldt
  • 13,561
  • 5
  • 60
  • 64
Ankit Bansal
  • 4,962
  • 1
  • 23
  • 40