C# – How to set test category for all tests in the class

cmstesttfsunit testing

I am using MSTest, and I want to set the same test category for all methods in test class at once, without setting TestCategory attribute to each method individually. How can this be done?

The most convenient and obvious way would be to set TestCategory attribute on class, but it can be applied to methods only.

The ultimate goal is to skip integration tests during test run on TFS check-in.

Best Answer

To be able to set the [TestCategory] attribute at the class level, install the “MSTest V2” TestFramework using NuGet.

Ref: https://blogs.msdn.microsoft.com/devops/2016/06/17/taking-the-mstest-framework-forward-with-mstest-v2/