4

Does branch coverage work on the following statement?

I expected a red indicator because the first expression only has tests where it is false and not true.

tax.Voided = P_tax.Amount == 1012312870000.42M || P_tax.Amount < 0.00M;

The first expression is always false and the second is sometimes true: ReportGenerator snapshot

Ryan Andres
  • 312
  • 3
  • 13

2 Answers2

13

Do not confuse reporting by ReportGenerator with OpenCover XML output; though until the OpenCover starts working on their own reporting visuals ReportGenerator is currently the best you will find for now.

Your problem here is the reporting tool does not report (red/green) coverage based on branch coverage only on sequence coverage.

You will need to look at the overview of branch coverage aginst the method (that is summarised at the top of the report) - for more detail view you should look at the XML report data for the method and perhaps compare that against the IL (where OpenCover gets the coverage information from).

Note: OpenCover does not know what language you wrote the code in all it sees is the IL that has been produced.

Shaun Wilde
  • 8,228
  • 4
  • 36
  • 56
  • 2
    I'm not sure why would anyone downvote an answer from the creator of OpenCover... – Igal Tabachnik Sep 08 '11 at 11:02
  • Thank you for pointing this out @Shaun, I found the branch info the XML: ... ... I can't find the documentation explaining these attributes, could you point me in the right direction? – Ryan Andres Sep 09 '11 at 05:38
  • @ryan-andres - there isn't much documentation at the moment as I haven't written it :) the closest I have is http://scubamunki.blogspot.com/2011/08/problem-with-sequence-coverage.html (and part two covering switch) all the information is driven from the IL produced - so you might want ILSpy or reflector to hand – Shaun Wilde Sep 09 '11 at 08:32
  • I just realized branch coverage isn't what I meant. Let's say I have just a single expression, var voided = amount < 0.00M;, how can I check that there are 2 tests for its true and false values. Branch coverage would have a visit count but does not guarantee both true and false values were tested. My workaround would be to do, bool voided; if(amount < 0.00M) {voided = true;} else {voided = false} because sequence coverage would work here. – Ryan Andres Sep 09 '11 at 16:34
  • The only way I think would be have a script that would check each branch point that shares the same offset (of the IL instruction) and check that you have a vc>0 for each path (note swtiches can have multiple paths). – Shaun Wilde Sep 09 '11 at 20:41
0

If your coverage tool doesn't understand that you can have several interesting "coverable" entities within a line, you will likely get a report that your line is covered if any coverage entity in that line is covered.

Tools that instrument class files are, AFAIK, limited in this way because the class files on only contain information relating class code to source lines, not partial lines.

Our Java Test Coverage tool (and other members of our test coverage tool famility) don't instrument the class code files. Rather, they instrument the source code, and track the partial line information (starting line/column, ending line/column) accurately.

Our tool wouldn't have any trouble showing the coverage on the individual parts of the statement.

Ira Baxter
  • 93,541
  • 22
  • 172
  • 341