Search code examples
unit-testingtestingnunitcategorization

Tests categorization


I would like to know what's the "best practice" about categorizing tests using attributes (like the Category attribute of NUnit) ?

Do you categorize them by functionnal scope of the application, by kind (unit test, end-to-end tests, smoke tests, integration tests, etc), by technical category (long running, web request, etc) or a mix of each ?

To summarize, I don't want to re-categorize thousands of tests in few months, so what's the best strategy ?

Thank you in advance for your answers !


Solution

  • Counter question: why do you want to categorize thousands of tests right now? What do you hope to accomplish. No need to do it at all if you don't know. :-)

    My answer would be that Categories are really for the use of developers, because they can easily change them in the code when they need to. Sometimes, for example, it's handy to mark all the slow-running tests so they can be excluded from a run. You can mark all the fast running tests instead but one hopes there are many many more of them. Similarly, if you need to run tests when the database is not available, use categories on those tests that need it unless they are already grouped by namespace.

    Use namespace grouping for your more permanent organization of tests. The power of categories is that they cut across your namespace and fixture organization. Use them sparingly when that sort of crosscutting is what you need but don't set up a rigid system of categories.