From: Roger B. <ro...@ro...> - 2012-03-08 04:50:31
|
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 07/03/12 12:39, Kevin Bedard wrote: > Hello. Are branches counted by counting the newline chars in my code? > Or does it count the statement separators? Or other? It works on the bytecode, not the source and does both line and branch based coverage. Use 'javap' on a .class file to see what the insides look like (before you have run Cobertura on it). The line based coverage merely checks that for any line that has corresponding bytecode, any of that bytecode has been executed. > If (exp1) or (exp2) then action1; The bytecode for that line looks something like this: evaluate exp1 if true goto body evaluate exp2 if false goto end :body evaluate action1 :end If exp1 was always true then the exp2 bit is never executed. Branch reporting would look at the above byte code and see that there are 2 gotos and check that they are both executed. (I don't know exactly what it does behind the scenes - that is the principle to make sure all the bytecode is executed.) > How does Cobertura report coverage on such a statement? Look at the top of the HTML report. There is one column for line coverage and one column for branch coverage. In the listing lines where all the code has been executed are shown with a green margin. Lines where not all branches have been taken are highlighted in a pinkish red. Roger -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (GNU/Linux) iEYEARECAAYFAk9YNnAACgkQmOOfHg372QTZGQCfeWL5uj+eWLsR0XV/JBkwlc9k +EgAn1RjOOvMrCEX3k7J/x2DHEReEUkj =U+B2 -----END PGP SIGNATURE----- |