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 :)

nCover.png

Thanks in advance,
Jim

1
9 comments

Addendum: I have gotten around this issue by using the following

DOTcOVER.png

Regards,
Jim

0
Hi Jim,

Unfortunately, there's a known issue with closing braces in dotCover: dotCover considers as uncovered closing braces in methods that always return with exception.
We have a corresponding issue in our tracker: http://youtrack.jetbrains.com/issue/DCVR-4846. You are welcome to track its status, vote and comment.
Sorry for the inconvenience. 

Regards.
0

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...)

0

Hi

You can try something like this:

And your test method:

0

this problem still exist 9 years later...

4

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.

0

I have this issue in 2023 with Rider + dotCover on OSX.  A real shame it hasn't been fixed in over a decade.

0

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));
   }

 

0

Please sign in to leave a comment.