Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can MsTest unit tests be grouped in categories

In MbUnit one can do something like this:

[Test]
[TestCategory("Bad Arguments")]
[TestCategory("Fast")]
[ExpectedException(typeof(ArgumentNullException))]
public void TestCopyWithBadHref()
{
   . . . 
}

Note these two:

[TestCategory("Bad Arguments")]
[TestCategory("Fast")]

Since TeamBuild can be integrated with MsTest to perform gated check-ins and/or run at night, it is a great feature! However, given that some tests can run for a long time, it is convenient to separate them into the tests that should run before every check-in is confirmed, and the tests that should run at night instead due to their duration as well as other factors.

One way to go about achieving this might be creating several projects - one for slow tests, one for fast tests, etc. However, this separation is inconvenient. Project dependencies would not feel as natural, plus some tests can be in more than one logical category.

It would be great if MsTest had something similar to what MbUnit has had for a long time. For instance, one can run MbUnit.Cons.exe and specify the category to be used with a command-line switch.

How can I achieve the same using MsTest? We are a MSFT shop, and I failed to sell MbUnit to my co-workers.

like image 563
Hamish Grubijan Avatar asked Nov 24 '10 18:11

Hamish Grubijan


People also ask

Is MSTest a unit testing framework?

The MSTest framework supports unit testing in Visual Studio. Use the classes and members in the Microsoft. VisualStudio.

What is test category?

Test category means one type of test or group of tests specified by rule under sub. (4) for similar materials or classes of materials or which utilize similar methods or related methods.


1 Answers

You can use the /category option to filter the tests in VS 2010.

It uses the testcategory attribute. Details on the /category option.

C# code might look something like this:

[Description("test 123456"), TestCategory("Edit Tests"), TestCategory("Non-Smoke"), TestMethod]
public void VerifyEditsPersist()
like image 67
Mike Zboray Avatar answered Oct 19 '22 01:10

Mike Zboray