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# (7)
  • Deals (2)
  • Events (11)
  • Patterns (4)
  • Podcast (5)
  • ReSharper (2)
  • TFS (1)
  • Uncategorized (6)
  • Unit Tests (1)
  • Unity Application Block (7)
  • What Burns Me (1)

Recent Posts

  • 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

Twitter

  • Made it to Houston airport in time. Rush hour traffic is brutal-5 hours ago
  • Just wanted to mention that @olegsych (Tampa C# MVP) has finally joined Twitter!!-9 hours ago
  • RT @unclebobmartin: Nancy Pellosi: "We have to pass the bill so that you can find out what is in it."-14 hours ago
  • any of your books preloaded on it? RT @ambroselittle: RT Win a Kindle at #MIX10. Follow @Infragistics to learn how.-1 day ago
  • RT @esawdust: RT @HacknMod: 137 Years of Popular Science now Available for Free http://bit.ly/bRNNip-1 day ago
  • Running Win 7 64-bit? Fix the broken preview thumbnails for PDF files. http://bit.ly/dAVVnH-1 day ago
  • Don't forget to follow @OrlandoCC for the latest news on the Orlando Code Camp later this month-1 day ago
  • Lots of buzz about Amazon releasing a better browser for the #Kindle, I'd rather see better EBook oranization via Folders.-1 day ago

Comments

  • 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
  • Jeff Odell on Resharper Tip #1 – Highlight Usages

Recent Entries

  • 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
  • POCO and Unity Application Block Part II
  • POCO and Unity Application Block Part I
  • Random Selection of Posts

    • POCO and Unity Application Block Part II
    • Installing VS 2010 in XP Mode
    • Mix08 Videos Posted Online
    • Call for Speakers
    • Top Developer Podcasts Part II
    • Presentation on the Unity Application Block at the Sarasota Users Group
    • Alt.NET Podcast Launched!
© 2008 Randy Patterson. WordPress. Free email sender software
Theme designing by Mark Hoodia