views:

51

answers:

3

I'm working on a C# .net project using Visual Studio 2008, so my question is specifically for this case. However, the question should be the same to many other environments, so I'll be glad to hear opinions from people in similar environments.

My solution is organized in several projects. All of which have some belonging unit tests. There are several ways the tests can be structured, and I've felt the best way to handle this was to have one corresponding ".Tests"-project pr project. I.e. I have the projects:

MyApp.Model
MyApp.Utils

Giving me the corresponding projects for the tests;

MyApp.Model.Tests
MyApp.Utils.Tests

This very nicely wraps all tests that longs together into one project, giving one assembly for each "group" of tests. I've felt comfortable with this being the best way for a while, but as the application grows I get 2 new projects instead of one each time I add a new one. Now I think it's starting to get messy, and I'm considering to add one single MyApp.Tests project to hold all my tests. The tests can still be nicely structured with a good file structure inside this project.

So; how are people structuring their tests?

+1  A: 

1 project for ALL tests.

Then comes folders & namespaces integration/unit/regression => then project1/project2/project2.

Configure your test runner to run only unit tests (i.e. - by namespace) and that's it!
Faster build time yet still nicely structured solution guaranteed (of course there are always exclusions where this approach might not be appropriate).

Arnis L.
+1  A: 

I usually follow the same structure as you do here. It gives a nice consistent pattern where you get the corresponding test directly beneath the project that is tested in the Solution Explorer. Makes it easy to navigate and find out where the tests are located and what code is beeing tested. Also makes it easier for other people who are familliar with this structure to get into your code.

If you have a problem with too many projects, you should use folders more actively. Group the projects (and their tests) into well named and well structured folders.

erikric
And with "grouping folders and their tests into folders" you're referring to solution folders? And are you suggesting one folder for each "project", containing both the project itself and its corresponding test-project? Hence one folder for e.g. MyApp.Utils and MyApp.Utils.Tests?
stiank81
Solution folders, yes, but not one folder per project. We usually cluster projects with a common purpose or domain together in folders. I.e. one folder for GUI-components, another for domain objects, one for db-related stuff etc.
erikric
+1  A: 

For each project a separate test project, i.e. Project.Tests. Then I store all my test projects in a single Solution Folder, i.e. "Test Projects".

Tadas
I use the same approach. When a solution starts to get messy with many projects, solution folders is a good way of organizing it, tests or otherwise.
jonsb
Actually I wasn't aware of the Solutions folders. This definitely seems to be what I'm looking for! Will have a go on it. Thx!
stiank81
Confirmed. Solution Folder was just what I needed! This also prevents problem of a single Test-project if I want to reuse some of the projects but not all in a new solution. I would need a completely new test-project which shares some tests with the other solution - instead of just reusing the relevant projects like I can using a Solution Folder. Thx!
stiank81
It's a trade off. With bunch of projects it get's slower with every project you add (arrrrgh.... hate that). That's why my preference is to keep them all in one. And you can fix `reuse some of the projects but not all in a new solution` with removing project references and referencing assemblies directly from releases folder (that involves making your build more sophisticated). Tests are not production code - they don't have to be separated into components physically.
Arnis L.