The Artima Developer Community
Sponsored Link

.NET Buzz Forum
What should you write in a test Assert message?

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
What should you write in a test Assert message? Posted: Apr 11, 2005 6:58 AM
Reply to this message Reply

This post originated from an RSS feed registered with .NET Buzz by Roy Osherove.
Original Post: What should you write in a test Assert message?
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
The Assert message in a test is one of the most important parts. It's there to tell us what went wrong with our code. what we expected to happen but didn't, and what should have happened instead. A good assert message helps us track bugs and understand unit tests more easily.
Sadly, most developers new to automated unit tests usually leave the assert messages to last (which means they never get written correctly).
 
DO
  • Express what should have happened or what did not happen
    • "Foo should have thrown an exception"
    • "Foo did not throw any exception" (not as good as the previous one)
    • "Foo should have returned a new ID"
    • "Foo should not allow negative numbers as parameters"
    • "Foo should open the connection before returning it"
    • "Foo did not open the connection before returning it"
    • "Person class did not have a valid GUID by default"
Don't
  • Provide empty or meaningless messages
  • Provide messages that repeat the name of the test case
  • Provide messages that simply state the test inputs
 

Read: What should you write in a test Assert message?

Topic: You still think XML is angle brackets? Indigo tells you otherwise... Previous Topic   Next Topic Topic: I have hit the 800 Mark

Sponsored Links



Google
  Web Artima.com   

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