Friday, March 11, 2016

xUnit.Net replacement to TestCategory in MSTest

If you are migrating your Unit Tests from MSTest to xUnit.Net, you may be wondering how to migrate the TestCategory attribute available in MSTest over to xUnit.Net.

Well, fortunately, you can accomplish that pretty readily using the Trait attribute!!

Therefore, instead of something like this in MSTest:

[TestMethod, TestCategory(Unit)]

You will decorate your xUnit.Net Unit Test methods like this:

[Trait("Category", "Unit")]

Even better is that you can simply decorate your entire class with this Trait attribute so that you do not have to categorize your individual Test methods!

[Trait("Category", "Unit")]
public class UnitTest1

Unfortunately, when you run your tests in Test Explorer in Visual Studio, they still display in the following manner:

On the bright side, if you install the Resharper extension for xUnit (, you will instead get Test Windows similar to the following:

You can learn how to download and install the Resharper extension for xUnit from here:

No comments:

Post a Comment