Follow @RoyOsherove on Twitter

Test maintainability: consider creating a test fixture "per method" instead of "per class"

If you find yourself writing lots of tests for a single method on your tested class - consider making a specific fixture for just one method or feature. It would make the class more maintainable and logically sound. 
For example, a complex Login class might have one "IsLoginOK" method that has dozens of unit test for various logical angles and features.
 
You might have a fixture that looks like this:
 
[TestFixture]
public class LoginManagerTests_IsLoginOK
{
   [Test]
   public void ReturnsFalseOnNonExistingUser()
   {
   ...
   }
 
}
 
note that:
  • The class name suggests the main feature or function being tested by postfixing it to the name
  • The is no need to prefix methods in the class with the method name since it is clearly the only method being tests. Each test case is a variation of feature of this method.
  • You might end up with multiple class test fixtures for one tested class. That's OK, just remember to put them under a specific folder in your test project with the name of the tested class like this
    • ProjectName
      • LoginManagerTests
        • LoginManagerTests_IsLoginOK
        • LoginManagerTests_ChangePassword
        • LoginManagerTests_General
  • You would probably end up with a class that tests various "small" features which were left over from other fixtures. name it to [TestedClass_General] or [TestedClass_Misc] so that it's testing purpose is understood. 

Another Entlib example: Separate integration tests from unit tests (and learn to know the difference)

Enterprise library -- Test usability and "runnability"