Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

MSTest V2: First Impressions

DZone's Guide to

MSTest V2: First Impressions

Blogger Dror Helper offers his opinion and first impressions on the new MSTest V2.

· Agile Zone
Free Resource

Reduce testing time & get feedback faster through automation. Read the Benefits of Parallel Testing, brought to you in partnership with Sauce Labs.

It’s been a while since I’ve tried a new Unit Testing framework. It seemed that between NUnit, XUnit, and MSTest, I had enough to choose from. I’ve always tried to be pragmatic when choosing a test framework for a new project and when suggesting one to a new client.

Although all .NET unit testing frameworks are pretty similar, there are some differences between them – and I’m not talking about how they call the “Test” attribute.

It always frustrated me that MSTest didn’t seem to change much since it was introduced back in 2005 while both XUnit & NUnit have improved over time with new ideas that made unit testing easier to adopt.

One of the features I missed the most was parameterized unit tests – the ability to write a test once and run it several times with the same input. Since MSTest is widely used it was frustrating to see good developers write bad tests just because that feature was missing.

Over the years, I grew tired of waiting for that support and I’ve tried implementing it myself – with some success but without a lot of problems:

And then those solutions stopped working and I’ve stopped using them.

That’s why I was happy to find out that not only is Microsoft working on a new MSTest V2, but it will have the parameterized tests I’ve always wanted.

On top of that, getting started with it is simple. You no longer have the create a special “Unit Testing” project – any class library will do.

Image title

And then just add MSTest.TestFramework & MSTest.TestAdapter using NuGet and you’re ready to go. (Don’t forget to mark Include Prerelease.)

Image title

Image title

And writing tests just works just like before – even better now that we have the ability to write tests with RowTests:

[TestClass]
public class TestFrameworkTest
{
    [TestMethod]
    public void SimpleTest()
    {
        Assert.IsTrue(false);
    }

    [DataTestMethod]
    [DataRow(1, 2, 3)]
    [DataRow(2, 2, 4)]
    [DataRow(3, 2, 6)]
    [DataRow(5, 2, 7)]
    public void RowTest(int a, int b, int result)
    {
        Assert.AreEqual(result, a + b);
    }
}

And it works! I run the tests and a separate test runs from each row.

Image title

At the moment there is no way to run only one row – you have to run them all. This means that I cannot debug a single row, which can become very painful with multiple rows. Although NUnit (and XUnit) still have better row testing functionality, at least now I can write (and teach others how to write) proper tests even when a client has chosen to use MSTest (due to other good reasons).

Seems that MSTest is changing and I can’t wait to see what other new features will come next.

The Agile Zone is brought to you in partnership with Sauce Labs. Discover how to optimize your DevOps workflows with our cloud-based automated testing infrastructure.

Topics:
unit testing ,mstest ,mstest v2 ,testing

Published at DZone with permission of Dror Helper, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}