'Visual Studio 2022 Code Coverage Analysis Unusual Behavior
I am using NUnit, NSubstitute, and Visual Studio 2022 for testing an ASP.NET Core 6 Service. I'm seeing some results that I don't understand. Here is a screen capture, showing the code and the coverage results:
The color coding is saying that line 71 (throwing the new exception) is covered, but the if on line 69 is only partially covered. How is this possible? To get to line 71, both of the conditions on either side of the && operator must be executed.
Solution 1:[1]
Answering my own question...
The issue was that I didn't have a test case where customer.Dead.HasValue == false, or said another way, where customer.Dead == null. The database and entity allow for a null value here, but there was no unit test of null.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Kevingy |

