How can I achieve complete code coverage for OR statements in Visual Studio?
I'm just wondering how code coverage works in visual studio. Here's a very basic version of my script.
if (A || B)
{
//Do the thing
}
I have 4 unit tests to assert if a "thing" is being executed or not, checking all possible permutations of A and B like this:
- A '+ B' Statement: not done
- A '+ B Approval has been done
- A + B ' Assertion was made
- B + A . The approval has been completed.
All these tests pass predictably. The problem is that I am still getting a "partially" covered result for the if condition itself. As far as I know, I have all the possibilities. Is there something missing here?
Thanks in advance, feel free to redirect me if there is already an answer for this but I couldn't find it. In fact, the answers I found say I should have 100% coverage, so I wanted to see what you guys think.
Something of a note:
I'm not sure if this matters, but technically A and B are comparing properties of two instances of the same class, so the code actually looks like this:
if(oldObj.ValueA != newObj.ValueA || oldObj.ValueB != newObj.ValueB)
{
//do the thing
}
Hope this is enough, thanks again. I realize that being obsessed with over 100% coverage is silly, but it's mostly out of curiosity.
source to share
No one has answered this question yet
Check out similar questions: