Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unit testing in VS2010 - "Debug" passes, "Run" fails

I'm having a strange issue with unit testing in Visual Studio 2010. I have a test that passes when I use "Debug test" (without any breakpoints), but failes when I use "Run test". This test uses external dll's, so I can't debug it properly.

Do you know of any reason why a situation like this is possible? Why "Debug test" is different than "Run test", when all other parameters are the same?

like image 981
Augustina Avatar asked Jan 29 '12 16:01

Augustina


People also ask

How do I run unit tests in debug mode?

To start debugging: In the Visual Studio editor, set a breakpoint in one or more test methods that you want to debug. Because test methods can run in any order, set breakpoints in all the test methods that you want to debug. In Test Explorer, select the test method(s) and then choose Debug on the right-click menu.

How do I run a JUnit test case in debug mode?

In the case of a test failure you can follow these steps to debug it: Double click the failure entry from the Failures tab in the JUnit view to open the corresponding file in the editor. Set a breakpoint at the beginning of the test method. Select the test case and execute Debug As>JUnit Test from the Debug drop down.


2 Answers

Switch you solution to Release mode instead of Debug, run a full build, switch back to debug and retry and let me know the outcome, I think the tests will pass....

like image 57
Christopher Maddock Avatar answered Oct 07 '22 18:10

Christopher Maddock


There can be several reasons, but to pin-point one, you'll have to give us some code to work with.

It could be code exclusion:

#ifdef _DEBUG
//do something
#endif

This will only be executed in debug mode.

It could be optimizations. Although they shouldn't normally affect the behavior, you shouldn't rely on destructors or copy constructors being called.

If you're doing any hacking inside the code, it might also only be valid for debug.

like image 30
Luchian Grigore Avatar answered Oct 07 '22 17:10

Luchian Grigore