views:

1473

answers:

4

The Microsoft unit testing framework has suddenly gone on strike.

When I try to run tests in VS2008, I get a dialog with the message "VSTestHost.exe has stopped working".

I have Visual Studio Team System 2008 (version 9.0.30729.1 SP) running on Vista with all updates applied.

The "Problem reports and solutions" suggests that I "Upgrade to the latest retail version of Visual Studio Team Edition for Software Testers" which is not right.

I have tried rebooting.
I have tried "devenv /resetuserdata"

These made no difference.

I'd like to go back to MbUnit based on this nonsense, but that's not my choice.
Any suggestions on how to fix this?

+1  A: 

I have found the issue that I was asking about, and it was my fault. I had coded a stack overflow: I refactored some code into an extension method, renamed it to match the Linq extension method that it called, and so it just called it self recursively.

The lessons to learn from this:
1: "select" isn't broken. I was too quick to blame the framework, due to its bad reputation.

2: But it did have a pathologically general and entirely misleading error message.

In cases where the error message is that bad, a good debugging technique is to try to pin down what does and what doesn't cause the error. In my case, the breakthrough came as soon as I noticed that it wasn't "the test run" that was failing, it was only runs containing Sql database tests - domain object and mock repository test could run just fine, so there had to be something about the code that it was running. And that the debugger would step into the tests. I had assumed from the calamitous errors that it wasn't even getting that far.

Anthony
A: 

Have you tried running a repair on Visual Studio or even resetting back to factory settings?

To reset to factory settings, run devenv /ResetSettings from the run window.

Kieron
+1  A: 

It's important to note that while the error message explaining that the VSTestHost.exe stopped working wasn't very descriptive. In the test results there is a link that says "Test run completed" (or in your case it would have said "Test run failed") when clicking on this you would have seen the exact error message that occurred which caused the test host to fail (the stack overflow exception).

They kind of bury that information, but it's useful to know especially when the host doesn't crash but some of the tests simply don't work, sometimes the information as to why can be found in that link.

+4  A: 

This is usually due to something wrong in the code like an endless loop, or a circular reference.

I had the same issue and realized that it was my code that was messing up, and the test framework was simply protecting itself against my code by shutting itself down.

The key for me was that the same thing happened with two different testing frameworks. So it had to be my code.

Mitch Labrador