I'm not using the constructor/destructor for initialisation and cleanup; instead I'm using the TEST_METHOD_INITIALIZE/CLEANUP macros that call setup and cleanup code before each method is called. This is very similar to my previous article…in fact it's so similar that all I need to do is redefine my macro for MS_TEST_CASE_METHOD and define REQUIRE/FAIL and I'm done!
We need a different test runner for native tests:
12345678910111213141516171819202122232425
C:\Projects\NativeTestProject>"C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe" /Logger:Trx debug\NativeTestProject.dllMicrosoft(R)TestExecutionCommandLineToolVersion11.0.60315.1Copyright(c)MicrosoftCorporation.Allrightsreserved.Startingtestexecution,pleasewait...PassedMethod1FailedMethod2ErrorMessage:AssertfailedStackTrace:atManagedTestProject::TestWithoutInitializeAndCleanup::Method2()inc:\projects\nativetestproject\unittestcatch.cpp:line23PassedMethod1FailedMethod2ErrorMessage:AssertfailedStackTrace:atManagedTestProject::TestWithInitializeAndCleanup::Method2()inc:\projects\nativetestproject\unittestcatch.cpp:line53ResultsFile:C:\Projects\NativeTestProject\TestResults\name_machine2013-10-2820_59_53.trxTotaltests:4.Passed:2.Failed:2.Skipped:0.TestRunFailed.Testexecutiontime:0.8892Seconds
The code is identical to the managed/Catch example, so Catch works just the same: