Randy Patterson

Code To Live, Live To Code

  • Home
  • About

21

Sep

Useless Unit Test

Posted by randypatterson  Published in What Burns Me

This is one of the most useless unit tests I’ve encountered

/// <summary>
///A test for GetByLegalCaseID (int)
///</summary>
[TestMethod()]
public void GetTicketByLegalCaseID_Test()
{
    TicketEntityModel target = new TicketEntityModel();
    int ID = 1;
    TicketDataSet actual = target.GetByLegalCaseID(ID);
 
    Assert.IsNotNull(actual, "TicketDataSet was not returned.");
    Assert.IsNotNull(actual.Citation, "No Citation table was returned.");
    Assert.IsTrue(actual.Citation.Rows.Count > 0, "No Citation rows were returned.");
    Assert.IsNotNull(actual.Ticket, "No Ticket table was returned.");
    Assert.IsTrue(actual.Ticket.Rows.Count > 0, "No Ticket rows were returned.");
}

 

Unit tests in the Entity Model should concentrate on testing business logic, not Data Access Layer (DAL) logic. Unit tests for DAL objects test data access issues.   Furthermore,  this Unit Test simply checks to see if the current database has a record with an ID of 1 and, therefore, is non-deterministic. It can fail for many reasons that have nothing to do with the business logic. If GetByLegalCaseID has any business logic in it then unit tests should to be written to test that logic and the dependencies on the DAL would be mocked so a previously setup DataSet is returned with known values. This falls under the “What Burns Me” category. 

Bookmark It

Add to Del.icio.us Add to digg Add to DotNetKicks Add to DZone
Add to Google Bookmarks Add to reddit Add to Slashdot Add to Stumble Upon
Add to Technorati Add to Twitter Add to Yahoo My Web
5 comments

RSS

  • Log in
  • Entries RSS
  • Comments RSS
  • WordPress.org

Tags

Azure CodeCamp IoC Podcast Presentation ReSharper TFS Unit Test Unity VS2010

Categories

  • C# (8)
  • Deals (2)
  • Events (11)
  • Patterns (4)
  • Podcast (5)
  • ReSharper (3)
  • TFS (1)
  • Uncategorized (7)
  • Unit Tests (1)
  • Unity Application Block (7)
  • What Burns Me (1)

Recent Posts

  • Support The National Day of Prayer
  • ReSharper and the Method Group Refactor
  • Moved my Blog
  • Installing VS 2010 in XP Mode
  • TFS Basic Version

Twitter

  • RT @dotnetblogs: #shanselman: A New Podcast for Developers - This Developer's Life http://ow.ly/18RfJQ-2 hours ago
  • going to go see vampires suck with my daughter. I'll have to laugh when she does because I wont understand a thing-3 days ago
  • WIndows Live Sync is the new Live Mesh http://tcrn.ch/ceh2oR-4 days ago
  • got a signed copy of @sdorman new C# book!!-1 week ago
  • RT @devfish: tampa/orlando web firestarters - http://bit.ly/9opxrF #fldev-1 week ago
  • I am constantly impressed with the quality and content of the RadioLab Science poscast http://bit.ly/Od4Ek-1 week ago
  • Reality is frequently inaccurate - Douglas Adams-1 week ago
  • Reminder: IASA Meeting tonight: @absolutdeno presenting Delivering SOA with Silverlight and WCF RIA Services http://bit.ly/aRCSuc-1 week ago

Comments

  • olegsych on Moved my Blog
  • Ed Holloway on TFS Basic Version
  • Jeff P on The Power of the Predicate<T>
  • Jeff Odell on Beginning ReSharper
  • Jeff Odell on POCO and Unity Application Block Part I

Recent Entries

  • Support The National Day of Prayer
  • ReSharper and the Method Group Refactor
  • Moved my Blog
  • Installing VS 2010 in XP Mode
  • TFS Basic Version
  • Windows Azure Commercial Release this year!
  • Orlando Code Camp 2009 – Unity Presentation Slides and Code
  • Speaking at the South Florida Code Camp
  • Call for Speakers
  • Beginning ReSharper
  • Random Selection of Posts

    • Unity Application Block Event Broker
    • Visual Studio 2008 Express Released
    • POCO and Unity Application Block Part I
    • Free Conference Calls in less than 60 seconds
    • Welcome
    • I am Speaking at the Next IASA Meeting
    • MSDN Article on Dependency Injection
© 2008 Randy Patterson. WordPress. Free email sender software
Theme designing by Mark Hoodia