Limit Test Explorer Runs to Specific Unit Tests

I use Unit Test projects in Visual Studio using the NuGet MSTest.TestFramework package. While most of the tests are unit tests, some are integration tests (because it is so handy to run run them in the Test Explorer, too). In the same project, I may have may both types.

To separate the tests into “unit tests” versus “other” buckets, I use the TestProperty attribute. This allows me to easily select the desired test set.

Visual Studio Test Method “Trait” Attribute

Tag all your test methods with the TestProperty attribute to give them a “Trait” name.

[TestMethod]
[TestProperty("UnitTest", "")]
public void VitalUnitTest()
{
    ....
}

Rebuild your project then add the Trait filter that matches the first TestProperty parameter to the Test Explorer UI. Only the methods with the matching TestProperty will show up. In my case, I have tagged a total of 13 methods with the “UnitTest” trait.