Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run/Group Tests by Category Attribute of NUnit in Visual Studio

I am trying to use the Category Attribute of NUnit with my Visual Studio Profession 2015. However, the attribute doesn't seem to be categorizing the Tests in the Test Explorer.

[Test]
[Category("ValidLogins")]

I tried this as:

[Test, Category("Login")]

But even that didn't work. Any suggestion?

like image 205
Rammohan Banda Avatar asked Sep 08 '16 10:09

Rammohan Banda


People also ask

What is category attribute in NUnit?

The Category attribute provides an alternative to suites for dealing with groups of tests. Either individual test cases or fixtures may be identified as belonging to a particular category. Some runners, including the Console Runner, allow specifying categories to be included in or excluded from the run.

How do I run multiple test cases in NUnit?

If you add a second parameter with the Values attribute, for per value of the first parameter, NUnit will add a test for every value of the second parameter. Another way to avoid having to write duplicate tests when testing the same behaviour with different inputs is to use TestCase attribute on the test itself.

What is test category in C#?

Effectively, using TestCategory lets you create a group of tests using any arbitrary system you want. This allows you to create (and run!) groups of tests that you feel are related without having to run every test in a class, a project or a solution.


1 Answers

By default, Visual Studio's Test Explorer Window groups tests by Outcome which groups by Passed, Failed and Not Run. Many people miss the options for changing the grouping.

You can right-click on a group and select Group By,

Grouping Unit Tests in Visual Studio

or there is a grouping dropdown in the upper left corner of the Test Explorer window.

Grouping Unit Tests in Visual Studio

Visual Studio groups tests by Class, Duration, Outcome, Traits or by Project. Traits map to NUnit's Categories.

like image 191
Rob Prouse Avatar answered Oct 28 '22 22:10

Rob Prouse