Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

ExcludeFromCodeCoverage ignored in optimized instrumentation mode?
Balfa
#1 Posted : Tuesday, December 17, 2019 2:21:59 PM(UTC)
Rank: Member

Groups: Registered
Joined: 12/7/2011(UTC)
Posts: 14
Location: Dallas

Thanks: 2 times
Was thanked: 2 time(s) in 2 post(s)
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())
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

YAF | YAF © 2003-2011, Yet Another Forum.NET
This page was generated in 0.022 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download