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.
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.