Gotchas: Upgrading your unit test projects to VS 2008

Monday, January 7, 2008 – 3:37 PM

Consider the following test…

  public void TestExpectedException()
      throw new ArgumentException("Bad argument");

All looks pretty trivial right? You’d expect this to pass and indeed on my VS 2008 box it works fine.

If you’ve upgraded your test project from VS 2005 then the reference to the UnitTestFramework assembly may refer to version (VS 2005). Oddly the unit test runner detects the version 8 TestMethod attribute and runs the test but fails to find the ExpectedException attribute because it’s version 8, not the version 9 expected by VS 2008. This causes the test to fail when the exception is thrown and the test runner is not expecting an exception.

How to fix it

To get your test working again you need to remove the existing UnitTestFramework assembly reference and replace it with the (VS 2008) version.

It seems that this is just one of the issues with upgrading test projects from 2005 to 2008 and has been covered on the MSDN forums (this fix for this specific issue is addressed in step 13).

Sorry, comments for this entry are closed at this time.