Reputation: 2045
I would like to optimize my unit test assemblies. Specifically, I would like to make sure that multiple developers can work concurrently without stepping on each others' toes. What is the best practice when creating unit tests? One unit test class per real class, unit tests broken up by concern rather than by class, one large unit test class for all classes (I doubt it), etc.??
Upvotes: 1
Views: 321
Reputation: 777
The approach that I have gravitated toward is a context specification style of unit testing that breaks your unit tests into groupings of behavior; for example If I am working on a new ASP.NET web page for a web site called the job status page I would have a directory structure like this:
unit-tests -> spec_for_job_status_page
where spec_for_job_status_page is the folder that contains the solution file, csproj file and related classes.
As far as the structure of the unit test classes are concerned I like to use a naming convention that follows the context specification style such as:
namespace spec_for_job_status_page
{
[TestFixture]
public class when_the_job_status_page_is_loaded
{
[SetUp]
public void context()
{
//write set-up code here for your test
}
[Test]
public void should_show_the_job_number()
{
//write the assertion code here. Should be a single line
}
}
}
Upvotes: 0
Reputation: 2192
I think the best way is to differentiate on behaviour. One behavior for each testclass. Which means severaltest classes for each class. A related question with example can be found here.
Upvotes: 0
Reputation: 2563
There are tree possible approach to organize unit tests:
Usually there are needs to keep several automated test assemblies:
Upvotes: 1
Reputation: 189484
I like the one test class for a class convention from java. This makes sure that you always know where to find a test and the test units are small enough to have many people working on them without having to much merging to do because they are all in one file.
It also enables you to run only the tests for one class alone if you have a rather larger test suite and you are working closely on this one class.
Upvotes: 2