How to Add a Category to All NUnit Tests in a Project

In NUnit we can use the category attribute to classify tests. This allows us to mark long running tests and then tell our test runner to run them on demand but not with the regular test run. All we need to do is to add a category to a single test (or a class):

Until recently that was all we needed and it worked great. Now we have a new requirement and we need to set a category for all test in a solution. The manual way is not feasible, so we need new approach.

To mark all tests in a project you can create (or reuse) an AssemblyInfo.cs file in your project and add this code:

Recompile your project and all tests inside will get the category BDD. You can now exclude this category in your test runner and the test will only run when you explicitly ask for it.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.