Daily Usage Issues

ExcludeFromCodeCoverage ignored in optimized instrumentation mode?

Started by Balfa on 1,917 views

If I switch from legacy to optimized instrumentation modes, my code coverage for a certain project drops from 78.23% to 50.33%. This project makes significant use of the [ExcludeFromCodeCoverage] attribute, and looking at the metrics screen, those classes that should be exclude are showing as 0.00% in optimized (whereas the percentage is hidden in legacy).

This seems to be happening mostly just for lambdas, as seen in this example (which only records 1 compiled and uncovered line):
using System;
using System.Diagnostics.CodeAnalysis;
using System.Timers;
[ExcludeFromCodeCoverage]
public sealed class MyTimer : IDisposable
{
private Timer timer;
public void Dispose()
{
this.timer?.Dispose();
}
public void Register(Action action, TimeSpan interval)
{
this.timer = new Timer(interval.TotalMilliseconds);
this.timer.Elapsed += (sender, e) => action();
}
}

But also in classes with async methods:

[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
static class Test
{
public static async System.Threading.Tasks.Task Hi()
{
}
}

(the above example shows 2 compiled and uncovered lines, the opening and closing braces of Hi())

Post a reply

Log in to reply.