I cannot achieve 100% code coverage for the "catch with rethrow" block in VB.NET source code. My workplace IDE is Visual Studio 2010 Ultimate. The following is an example of a simplified version of my real problem.
Source in C #: (a light blue background indicates full code coverage)

Equivalent source in VB.NET: (yellow background indicates partial code coverage)

MSTests for C # and VB.NET source (designed to cover 100% of the code)

Code Coverage Report

The code coverage report shows 100% for C #, but only 91.67% for VB.NET. It also shows 1 block of code in which 0 lines are not found in VB.NET.
Is this a problem with the tool? Or am I missing something obvious?
EDIT # 1: Sharing source code on @Raptor request
C # source code
public class CodeCoverage { public void DoWork(bool flag = false) { try { Thread.Sleep(1); if (flag) { throw new Exception("test"); } } catch (Exception ex) { throw new Exception(string.Format("something happened: {0}", ex.Message)); } } }
Source Code in VB.NET
Public Class CodeCoverage2 Public Sub DoWork(Optional ByVal flag As Boolean = False) Try Thread.Sleep(1) If flag Then Throw New Exception("test") End If Catch ex As Exception Throw New Exception(String.Format("something happened: {0}", ex.Message)) End Try End Sub End Class
Source Code for MSTests
[TestClass] public class CodeCoverageTest { [TestMethod] public void DoWorkTest() { var obj = new CodeCoverage(); obj.DoWork(); } [TestMethod] [ExpectedException(typeof(Exception))] public void DoWorkTest2() { var obj = new CodeCoverage(); obj.DoWork(true); } [TestMethod] public void DoWorkTest3() { var obj = new CodeCoverage2(); obj.DoWork(); } [TestMethod] [ExpectedException(typeof(Exception))] public void DoWorkTest4() { var obj = new CodeCoverage2(); obj.DoWork(true); } }
source share