Visual Studio 2008 Unit test does not pick up code changes unless I build the entire solution

Posted by Orion Edwards on Stack Overflow See other posts from Stack Overflow or by Orion Edwards
Published on 2010-05-05T21:18:37Z Indexed on 2010/05/05 21:48 UTC
Read the original article Hit count: 235

Here's the scenario:

  1. Change my code:
  2. Change my unit test for that code
  3. With the cursor inside the unit test class/method, invoke VS2008's "Run tests in current context" command
  4. The visual studio "Output" window indicates that the code dll and the test dll both successfully build (in that order)

The problem is however, that the unit test does not use the latest version of the dll which it has just built. Instead, it uses the previously built dll (which doesn't have the updated code in it), so the test fails.

When adding a new method, this results in a MethodNotImplementedException, and when adding a class, it results in a TypeLoadException, both because the unit test thinks the new code is there, and it isn't!. If I'm just updating an existing method, then the test just fails due to incorrect results.

I can 'work around' the problem by doing this

  1. Change my code:
  2. Change my unit test for that code
  3. Invoke VS2008's 'Build Solution' command
  4. With the cursor inside the unit test class/method, invoke VS2008's "Run tests in current context" command

The problem is that doing a full build solution (even though nothing has changed) takes upwards of 30 seconds, as I have approx 50 C# projects, and VS2008 is not smart enough to realize that only 2 of them need to be looked at. Having to wait 30 seconds just to change 1 line of code and re-run a unit test is abysmal.

Is there anything I can do to fix this? None of my code is in the GAC or anything funny like that, it's just ordinary old dll's (buiding against .NET 3.5SP1 on a win7/64bit machine)

Please help!

© Stack Overflow or respective owner

Related posts about unit-testing

Related posts about visual-studio-2008