The Artima Developer Community
Sponsored Link

.NET Buzz Forum
Test maintainability: consider creating a test fixture "per method" instead of "per class"

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Roy Osherove

Posts: 1807
Nickname: royo
Registered: Sep, 2003

Roy Osherove is a .Net consultant based in Israel
Test maintainability: consider creating a test fixture "per method" instead of "per class" Posted: Apr 11, 2005 12:58 PM
Reply to this message Reply

This post originated from an RSS feed registered with .NET Buzz by Roy Osherove.
Original Post: Test maintainability: consider creating a test fixture "per method" instead of "per class"
Feed Title: ISerializable
Feed URL: http://www.asp.net/err404.htm?aspxerrorpath=/rosherove/Rss.aspx
Feed Description: Roy Osherove's persistent thoughts
Latest .NET Buzz Posts
Latest .NET Buzz Posts by Roy Osherove
Latest Posts From ISerializable

Advertisement
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. 

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

Topic: When To Checkin When Doing TDD? Previous Topic   Next Topic Topic: INDA - Next events - INDIGO - SQL 2005 - C# 2.0 - Register now

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use