Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.NET unit testing projects organisation

What would you say is the best way to manage the unit tests in a large .net application? Is it better to add a test project for each separate project in the solution or one large tests project for all the tests in the rest of the projects?

For example if there are 10 projects in a solution, is it better to have 10 additional test projects or one large tests project would suffice for the whole solution?

I know there are some benefits offered by modular test assemblies, but pretty similar things can be achieved using tests categories. Compilation takes longer with many projects, but you can exclude the projects you don't need at that moment, while if you have one single project you can't do that, but the compilation takes a little bit less time.

Please outline advantages/disadvantages for each choice in your answers.

like image 592
alxbrd Avatar asked Apr 24 '12 14:04

alxbrd


People also ask

What is .net unit testing?

ASP.NET MVC 5 for Beginners In computer programming, unit testing is a software testing method by which individual units of source code are tested to determine whether they are fit for use.

Is NUnit better than MsTest?

The main difference is the ability of MsTest to execute in parallel at the method level. Also, the tight integration of MsTest with Visual Studio provides advantages in both speed and robustness when compared to NUnit. As a result, I recommend MsTest.


1 Answers

Phil Haack wrote a nice article regarding the structuring of unit tests. This has become my personal best practice when writing unit tests. Here is the link to his article http://haacked.com/archive/2012/01/02/structuring-unit-tests.aspx

As for your question, I would always create a separate project for unit test and name it with .UnitTests appended (I do this in order to distinguish between unit and integration tests). For example, if my main project is Sample.WebUI, the test will be Sample.WebUI.UnitTests.

It is true that unit tests add additional time to the compilation, but I consider that a minor issue. I am working on a solution with 17 projects (excluding unit tests) and it takes about 50-60 second to compile everything. It is just about enough time to take my eyes off the monitor and look at something else for a change :-)

Regarding the categories, if you have some daily builds that require tests to complete quickly then use them and distinguish them from those tests that take longer to complete (like integration tests). Also, if you are using TFS, using categories can help automate and test your checkins.

like image 198
Husein Roncevic Avatar answered Oct 05 '22 23:10

Husein Roncevic