I assume every (.NET-)developer today uses unit tests and do TDD (Test Driven Development) at some degree.
I have used NUnit and Visual Studio Unit Test Framework. NUnit is very simple to use and requires little extra coding. Visual Studio Unit Test Framework is also very simple to use, but I think Visual Studio does too much for me when a create a new test project by the wizard. E.g. it generates empty test methods for the assembly to test. I never use this “feature” anyway because:
1. It only create one test per method to test. Usually I want to test methods under different conditions/states, and want to create one test per condition/state.
2. I don’t agree with the naming of the methods.
Probably there are a lot of TDD gurus out there having an opinion about unit test naming conventions and where to write the tests. One of them is definitely Roy Osherove, who has written the book The art of unit testing. It is important to follow the same patterns and conventions within a development team, so I suggest to follow Osherove’s conventions.
Test project naming
I think it is a good idea to separate unit test from integration tests. (Take a look here for definitions and an explanation of the differences)
By placing these test categories in different projects (assemblies) with proper naming conventions, it is easier to configure a CI build server to e.g. run only unit tests on each check-in and all tests on nightly builds.
For unit test projects, use:
[ProjectToTest].Tests.Unit
For intergration test projects, use:
[ProjectToTest].Tests.Integration
Test class naming
Usually I make one test class per class to test, and I use the following naming convention for the class and file name.
Class name:
[ClassToTest]Tests
File name:
[ClassToTest]Tests.cs
Test method naming
I like the naming conventions described here.
The basic naming of a test comprises of three main parts:
[MethodName_StateUnderTest_ExpectedBehavior]
Examples:
Divide_DivisorIsZero_ExceptionThrown()
Divide_DividendIsZero_ReturnZero()
For happy-day scenarios, use:
[MethodName]_HappyDay
Example:
Divide_HappyDay()
f85d8134-31e5-4a0f-8c70-af83449d72f5|0|.0