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:
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:
- Remove the reference to the 9.0.0.0 version of the Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll.
- Go to Properties on your test project and set the Target Framework to 4.0.
- 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.
posted @ Tuesday, June 23, 2009 2:56 PM