Is there a way that I can get to the exception that was handled by the MSTest framework using the TestContext or some other method on a base test class?
If an unhand
I've been running into the same issue, there doesn't seem to be support for this. You can't even use ApplicationDomain's unhandled exception hook since if MSTEST didn't catch exceptions before they bubbled up that far, it would itself crash.
Possible workaround:
private delegate void TestImplDelegate();
private void RunTestWithExceptionLogging(TestImplDelegate testImpl)
{
try
{
testImpl();
}
catch (Exception e)
{
string message = e.Message; // don't warn about unused variables
// do logging here
}
}
[TestMethod]
public void test1()
{
RunTestWithExceptionLogging(test1Impl);
}
private void test1Impl()
{
// test code goes here
throw new Exception("This should get logged by the test wrapper.");
}
[TestMethod]
public void test2()
{
RunTestWithExceptionLogging(test2Impl);
}
private void test2Impl()
{
// test code goes here
throw new Exception("This should get logged by the test wrapper.");
}
It's certainly not optimal, but at least this way you don't have multiple copies of the exception handler code.
I would recommend filing a feature request for this at http://connect.microsoft.com/ (or see if someone else has already requested it, and add your vote.)