There is a well-known problem when unit testing managed C++ code in Visual Studio: unmanaged code calling back into managed can’t cross app domains and crashes unit tests, as documented here:
http://social.msdn.microsoft.com/Forums/is/vststest/thread/fc7bc074-ff05-407b-b646-d9e5532c6998
and in more details here:
http://lambert.geek.nz/2007/05/29/unmanaged-appdomain-callback
Using /noisolation flag is one solution but it works only when running tests outside of Visual Studio, meaning you can’t debug your tests in Visual Studio.
For me this is a huge thing. I have hard time understanding that Microsoft doesn’t want to address this issue since at least 2006. Discovering that even Visual Studio 11 beta doesn’t offer anything new here was a major disappointment.
So I turned to NUnit and started running my test with “Use a single AppDomain for all tests” selected. Disappointingly, NUnit displays the message: “An unhandled System.ArgumentException was thrown while executing this test: Cannot pass a GCHandle across AppDomains.” After that it crashes.
I was hoping that I will be able to both debug and avoid GCHandle AppDomain issue. Am I misinterpreting the meaning of the single AppDomain option? Does NUnit 2.6 execute the test in the separate AppDomain and is there still no option to change that?
According to this answer by Charlie Poole at NUnit group:
https://groups.google.com/forum/?fromgroups&hl=en#!topic/nunit-discuss/elG7oyCOyBw
NUnit main (driver) program executes in the different AppDomain from the code that gets tested. Single AppDomain means single only for all the code to test.
Charlie suggested using NUnitLite, which uses a single AppDomain for “everything” and, after testing 0.7 version, I am happy that I can debug my tests of C++/CLI code which uses gcroot.
UI integration of NUnitLite in Visual Studio would be a great additional bonus, but for now I can live without it.