Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Debugging native/managed C++ in VS 2010 with NUnit

Tags:

c++

nunit

Is there a way to set breakpoints and step through them using NUnit with a mixed project of native C++ and managed C++?

I have my SUT (Software Under Test) configured as a static library (native C++) I have my unit test suite as a separate project configured as a dll that depends on my previously stated library. I also added said library as a reference to my unit test project.

My tests run fine in NUnit, breakpoints just don't work.

Again, is there a way to get the breakpoints to work with NUnit with Native/Managed C++?

like image 726
NexAddo Avatar asked Nov 13 '22 16:11

NexAddo


1 Answers

The most convenient way to do this is to set up a custom tool entry specifying the path to NUnit as the command. For a VS2003 C# project, you can use $(TargetPath) for the arguments and $(TargetDir) for the initial directory.

With Visual Studio VS2005 this becomes a bit harder, because that release changed the meaning of the 'Target' macros so they now point to the intermediate 'obj' directories rather than the final output in one of the 'bin' directories. Here are some alternatives that work in both versions:

$(ProjectDir)$(ProjectFileName) to open the VS Project rather than the assembly. If you use this approach, be sure to rename your config file accordingly and put it in the same directory as the VS project file.

$(ProjectDir)bin/Debug/$(TargetName)$(TargetExt) to run the assembly directly. Note that this requires hard-coding part of the path, including the configuration.

If you would like to debug your tests, use the Visual Studio Debug | Processes… menu item to attach to NUnit after starting it and set breakpoints in your test code as desired before running the tests.

like image 91
Roel Van Nyen Avatar answered Jan 02 '23 08:01

Roel Van Nyen