Closing braces sometimes not being included in code coverage
Answered
Hi all,
I am experiencing an issue with dotCover where, in some circumstances, the closing brace of a method/constructor is highlighted as not being covered...
Has anyone else witnessed this, and if so, what's the solution? We have a 100% coverage on our code and situations like this are making that rather impossible :)
Thanks in advance,
Jim
Please sign in to leave a comment.
Addendum: I have gotten around this issue by using the following
Regards,
Jim
I do still have this issue (VS 2015) but I do not have sufficient permissions to view the content from the the link you provided. (I am logged in...)
Try this link: https://youtrack.jetbrains.com/issue/PROF-309
Hi
You can try something like this:
And your test method:
this problem still exist 9 years later...
I am also seeing the last brace marked as not being covered in an otherwise covered method. The brace is *not* after an exception. This is present in 2022.2.3.
I have this issue in 2023 with Rider + dotCover on OSX. A real shame it hasn't been fixed in over a decade.
This works 100% for me:
#pragma warning disable IDE0060
public static class AssertException
{
public static void ExceptionEquals(this Assert assert, Type expected, Action action)
{
if (expected == null)
{
throw new ArgumentNullException(nameof(expected));
}
if (action == null)
{
throw new ArgumentNullException(nameof(action));
}
try
{
Task.Run(action).Wait();
}
catch (AggregateException aex)
{
if (aex.InnerExceptions.Any(inner => inner.GetType() == expected))
{
return;
}
throw new AssertFailedException(GetMessage(expected, aex.InnerExceptions.Select(e => e.GetType())));
}
catch (Exception ex)
{
if (ex.GetType() == expected)
{
return;
}
throw new AssertFailedException(GetMessage(expected, new[] { ex.GetType() }));
}
throw new AssertFailedException(GetMessage(expected, null));
}
internal static string GetMessage(Type expected, IEnumerable<Type> actual)
{
var actualList = actual?.ToList();
if (actualList == null || !actualList.Any())
{
return $"Exceptions are different. Expect: <{expected}> Actual: <No exception was thrown.>";
}
return $"Exceptions are different. Expect: <{expected}> Actual: <{string.Join(", ", actualList)}> ";
}
}
Then the test code:
[TestMethod]
public void WmaCross_List_NotEnoughDataException_01()
{
const int fast = 14;
const int slow = 28;
var candlesticks = LoadTestData("BTCUSDT", TimeUnit.Days, 1, "BTCUSDT_days_1_1");
Assert.That.ExceptionEquals(typeof(NotEnoughDataException), () => Domain.ServiceObjects.Indicators.Calculations.WmaCross.List(candlesticks.Take(slow - 1).ToList().ToDataStoreCandlesticks(), fast, slow));
}