How to determine what block isn't covered here?

I have a block of code like this (class/property names have been changed to meet company guidelines):

if (output.ExecutionStatus == RuleExecutionStatus.Success &&
    !obj.ListOfObjs.Cast<ConcreteType>().Any(p => p.Id == o.Id))
{
    obj.AddConcreteType(output.ConcreteObj);
}

Before adding && !obj.ListOfObjs.Cast<ConcreteType>().Any(p => p.Id == o.Id) this line was 100% covered. I added one test, called Test 2 down below.

So, after adding the new test, this block is almost 100% covered; but I can't figure out what isn't getting covered. It states 1 block is not covered. The tests executing now have the following attributes:

  • Test 1: returns success, has 0 in ListOfObjs, no match, adds successfully.
  • Test 2: returns success, has 2 in ListOfObjs, 1 matches on Id, does not add.

What I've Tried

  • Adding a test that has 1 in ListOfObjs, no match, adds successfully. I thought maybe the issue was surrounding the fact that it didn't cover the Any case where 0 matched.
Jon Skeet
people
quotationmark

It sounds like you haven't got a test where the execution status isn't success - in other words, the first operand of your && expression is true for all tests, so you're not checking that it's relevant.

(In general, if you can remove some of your production code without any of your tests breaking, that's a bad sign - or it's a sign that it was non-functional, e.g. an optimization.)

people

See more on this question at Stackoverflow