Build/Test Issues

ExcludeFromCodeCoverage not working

Started by paulo on 2,925 views

Hi,

I'm using ExcludeFromCodeCoverage over method and continue showing in NCrunchMetrics

[ExcludeFromCodeCoverage]
[HttpPost("executemigration")]
[AllowAnonymous]  
public async Task<IActionResult> executemigration()
{
       await _mongoDbContext.EnsureIndex();
       return Ok();
}

Edited

Hi, thanks for sharing this issue.

ExcludeFromCodeCoverage doesn't work here because at a physical level, the attribute doesn't get applied to the compiler-generated IL structure that comprises the async code block.

It is possible for us to fix this. However, we can't find a way of doing so that doesn't massively impact performance of the instrumentation .. such that the fix is worse than the problem.

VSTest has the same issue. I'm not aware of this attribute working in such a scenario with any other runner either.

I recommend using code coverage suppression comments instead.

Post a reply

Log in to reply.