So, I’m biting the bullet and trying to get started with asp.net MVC, unit testing and TDD.
I have a vague understanding of the concepts involved, which is to say somewhat beyond the “Hello World” level, but still pretty green. I’m ready for the rubber to meet the road, but
I’ve found myself staring at the “New Project” dialog in VS for the last half hour… how, exactly, do you organize your unit tests?
I see that with the standard VS Unit Test project type, it creates a separate project for the unit tests. Is that how I should proceed when using NUnit? Or should the tests be placed in the same project as the code being tested?
None of the “getting started with unit testing…” type tutorials I’ve found seem to address this.
Tests should be maintained in separate projects because you don’t want to deploy testing code to a production environment. For a single-project solution, one test project is probably sufficient.
Internally, a test project can be organized in any way you find convenient, as long as it’s consistent. An ASP.NET MVC test project might have a ControllerTests folder with one test .cs file per controller, mirroring the MVC project structure to some degree. This makes the tests easy to find and relate to the code they’re testing.