.NET unit testing projects organisation

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.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)