When the STL detects a problem in debug mode, it calls _CrtDbgBreak() which normally displays a dialog box allowing you to debug the issue. However running under MSTest, nothing happens. No dialog box, MSTest may report success. I fixed this by hooking into _CrtDbgBreak() and triggering an assert(), which uses a different mechanism, the __debugbreak intrinsic. This triggers the familiar "Press 'retry' to debug" dialog in these cases.
int MyReportHook(int nRptType, char *szMsg, int *retVal)
{
if( _CRT_ASSERT == nRptType )
{
assert(false);
}
return 0;
}
TEST_CLASS(UnitTest1)
{
public:
TEST_METHOD_INITIALIZE(methodName)
{
_CrtSetReportHook(MyReportHook); // hook STL asserts.
}
TEST_METHOD(TestMethod1)
{
Assert::IsTrue( StripExtension( L"" ) == L"" ); // test for handling empty strings.
Assert::IsTrue( StripExtension( L"test.txt" ) == L"test" );
}
};