views:

49

answers:

1

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!

A: 

After a bit more digging, I fixed the problem:

  1. Show the list of references on the test dll
  2. Remove the reference to the code dll from the list
  3. Re-add it.

I then diffed the .csproj to see what had changed, and it was as follows

Old and broken

<ProjectReference Include="..\Base\Base.csproj">
  <Project>{1C61F557-24C5-4B4A-90A8-08D0DCEE15A1}</Project>
  <Name>Base</Name>
  <Private>False</Private>
</ProjectReference>

New and good

<ProjectReference Include="..\Base\Base.csproj">
  <Project>{1C61F557-24C5-4B4A-90A8-08D0DCEE15A1}</Project>
  <Name>Base</Name>
</ProjectReference>

The <Private>False</Private> bit apparently means "Copy Local" so this explains it. Note to self: Remember to set Copy Local to true for unit tests!

Orion Edwards
Is the code assembly in GAC?
Lasse V. Karlsen