Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you structure your NUnit tests on a large project?

I am interested in seeing if I can improve the way we use NUnit in a Visual Studio solution containing 30+ projects.

First, would you have one assembly of tests for every assembly in the solution, or would you try to keep the number of test assemblies down? I started off creating many test assemblies, but I think this is costing us a lot in terms of build time.

Second, what strategy do you use for managing those tests that are long-running, or require special environment configuration? I would like to write an MSBuild script that automates the running of our unit tests, but it needs to skip over the tests that would take too long or would not work on the build machine.

like image 603
Mark Heath Avatar asked Oct 06 '08 08:10

Mark Heath


People also ask

How do you write 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.


1 Answers

To answer your first question:

You can use categories to keep everything organised in a single assembly if that's how you want to go. As to whether it would cut down on build time, I would hazard a guess at perhaps, I don't think it'd be a huge amount overall though.

To answer your second:

You can use categories and the [Explicit] and [Ignore] attribute to tell NUnit which tests to run, and which tests you have to tell it to run before it will. You might also want to look at [Platform] or some of the other attributes, depending on what exactly your requirements on 'environment' are.

For instance, you could add an Explicit tag to all your long running tests. Then you would have to run these tests explicitly, NUnit won't run them automatically. Or add all these tests to a category, then when you run NUnit, tell it to explicitly not run that category.

like image 72
Matthew Scharley Avatar answered Oct 08 '22 23:10

Matthew Scharley