Only the new version (10.0.0.0) of Microsoft Test Tools work in Visual Studio 2010

Tests fail when you reference the wrong version of Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll in Visual Studio 2010.

I just tried to run a suite of tests in Visual Studio 2010 that had a reference to the 9.0.0.0 version of Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll. It turned out that the test runner that runs the tests did not want to recognize my version of the ExpectedExceptionAttribute and consequently failed my tests that expect exception. This is a thing to keep an eye out for since it appears to me it is a bug in the current build of Visual Studio 2010. There is no failing run or no error message. Just a failing test.

Here is how to replicate the error and how to avoid it:

In my case I opened up a test project that targeted the 3.5 version of the .NET Framework. It in turn references the 9.0.0.0 version of Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll.

However you can also create a new project, make it a test project, set the target framework to 3.5:

newtestproject

Then you add a new unit test class and add one single test to it like this:

[TestMethod, ExpectedException(typeof(NullReferenceException))]
public void TestMethod()
{
    throw new NullReferenceException();
}

    This test will fail. The test runner ignores the ExpectedExceptionAttribute since it is not of the right version.

    Then do the following:

  1. Remove the reference to the 9.0.0.0 version of the Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll.
  2. Go to Properties on your test project and set the Target Framework to 4.0.
  3. Now add a reference to the 10.0.0.0 version of the Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll.

Re-run the test. It works!

The big problem here is that you get a failing test that does not look like it should fail. Before you wrap your head around the reason for this it might be a second or two. At least it was for me.

HTH – Cheers

M.

This work is licensed under a Creative Commons license.

posted @ Tuesday, June 23, 2009 2:56 PM

Print

Comments on this entry:

No comments posted yet.

Your comment:



 (will not be displayed)


 
 
 
Please add 5 and 3 and type the answer here:
 

Live Comment Preview: