Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VSTestHost.exe has stopped working - can't run unit tests

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?

like image 806
Anthony Avatar asked Oct 24 '08 14:10

Anthony


2 Answers

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.

like image 185
Mitch Labrador Avatar answered Oct 15 '22 12:10

Mitch Labrador


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.

like image 21
Anthony Avatar answered Oct 15 '22 12:10

Anthony