Turning a class library project into a MSTest project (or using MBUnit, MSTest and other frameworks in one project)

I know it’s been a while. I’ve been busy talking about SyncFramework at the VSOne conference, helping a bit of at the Sync Framework forums and lot’s of studying going on. I promise I have some new longer posts coming soon.

Yesterday I wrote a unit test that I wanted other members on my team to execute this week to check for some problems. Where’s the problem you may ask? Well I personally like TestDriven.net and MBUnit whereas my colleagues rely on the testing suite in Team System. Fair enough, usually we don’t exchange that many tests (and no - I’m sorry about that myself actually - we don’t have continuous integration. But even if we did that probably wouldn’t be a major problem).

Anyhow I created my class library project and wrote my test. Worked great on my computer (don’t hit me for saying that). I then remembered that it needed to run under MSTest on the other dev machines. Fair enough, can’t be that hard. I referenced

Microsoft.VisualStudio.QualityTools.UnitTestFramework

and gave my methods additional attributes. (The top ones are MSTest, the bottom ones are MBUnit.)

[Microsoft.VisualStudio.TestTools.UnitTesting.TestClass]
[TestFixture]
public class EvaluatorTestSuite

[Microsoft.VisualStudio.TestTools.UnitTesting.TestInitialize()]
[TestFixtureSetUp()]
public void SetUp()

[Microsoft.VisualStudio.TestTools.UnitTesting.TestCleanup()]
[TestFixtureTearDown()]
public void TearDown()

[Microsoft.VisualStudio.TestTools.UnitTesting.TestMethod]
[Test]
public void Evaluate_ValidEvaluationModel_ReturnsValidEvaluationResult()

Then I went to the Test menu in Team System and wanted to execute all tests in this solution. But VS told me there aren’t any. Basically I figured out the test projects must have some special attribute that make them “testable”. They are basically just class libraries but they have a special Guid in their project file. Not quite sure why Microsoft would do that, seeing as they could just check for the attributes on the classes like TestDriven.net does, but ok. This is a quick solution to turning a class library into a MSTest testable project. Open the CSproj file of the class library project and just before the first propertygroup closes insert the following line:

{3AC096D0-A1C2-E12C-1390-A8335801FDAB};

{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}

Those two guids make it MSTest testable. And no, I didn’t have time to figure out why there are two and what they do exactly. If anybody cares to explain, I would love to hear about it. The file should look something like this:

Debug AnyCPU
9.0.21022
2.0
{5273D187-1B0D-40DC-A415-36761976438B}
Library
Properties
TheGrandestProjectOfThemAll
TheGrandestProjectOfThemAll
v3.5
512
{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}

Technorati Tags: MSTest,Team System,MBUnit