Unit testing in VS2010 - “Debugging” passes, “Launch” fails

I am having a strange problem with unit testing in Visual Studio 2010. I have a test that passes when I use the "Debug Test" (without any breakpoints), but fails when I use the "Run test". This test uses external dlls, so I cannot debug it correctly.

Do you know why such a situation is possible? Why is the "Debug test" different from the "Run test" when all other parameters are the same?

+5
source share
3 answers

Switch the solution to Release mode instead of Debug, start the full build, go back to debugging and try again and let me know the result, I think the tests will pass ....

+3
source

There may be several reasons, but in order to indicate one, you will need to provide us with some code to work.

This could be a code exception:

#ifdef _DEBUG
//do something
#endif

This will only be done in debug mode.

It can be optimization. Although they should not normally influence behavior, you should not rely on calls to destructors or copies.

If you do a hack inside the code, it can also be valid only for debugging.

+2
source

I suspect that you are accessing memory beyond boundaries. One of the main differences between debugging and release is that debug adds sets, if add-ons and special markers for memory allocation, to catch certain kinds of errors. This means that memory layouts often vary greatly between debug and release builds. I would suspect that you are accessing the memory outside, so the debugger does not catch where you find randomly a valid value in the debug version, but invalid in the release.

+1
source

All Articles