Codecoverage partially covered by tests (9 of 16 conditions). There is only 9 conditions

Our development teams code coverage started failing due to the way these test cases are written, why would the test cases say there are 16 conditions when there are only 9?

  • ALM used GitLab
  • CI system used GitLab
  • Languages of the repository C#
  • Steps to reproduce
NEW C# NULL syntax:
if (string.IsNullOrWhiteSpace(data?.ApplicationUnderwritingData?.Affordability?.OpenBankingDecision) ||
    data?.ApplicationUnderwritingData?.Affordability?.OpenBankingDecision != AffordabilityDecision.Approve)
    return false;
  • Potential workaround
    The work around is to have it written in the old way
OLD C# NULL syntax:
if((data != null &&
    data.ApplicationUnderwritingData != null &&
    data.ApplicationUnderwritingData.Affordability != null &&
    (data != null &&
        data.ApplicationUnderwritingData != null &&
        data.ApplicationUnderwritingData.Affordability != null &&
        !string.IsNullOrWhiteSpace(data.ApplicationUnderwritingData.Affordability.OpenBankingDecision) &&
        data.ApplicationUnderwritingData.Affordability.OpenBankingDecision != "A" )
    return false;

Hey there.

What tool are you using to instrument code coverage?


It’s coverlet that is doing the code coverage


SonarCloud is only reading this report, not actually involved in producing it. As a result, you may want to check the coverage report that is being produced and raise an issue with GitHub - coverlet-coverage/coverlet: Cross platform code coverage for .NET if the report shows that 16 conditions could be covered.

Thank you Colin, I have passed that information back to the development teams