The Artima Developer Community
Sponsored Link

.NET Buzz Forum
Tests should reflect required reality

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
Tests should reflect required reality Posted: Apr 5, 2005 3:54 AM
Reply to this message Reply

This post originated from an RSS feed registered with .NET Buzz by Roy Osherove.
Original Post: Tests should reflect required reality
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

One of the most common mistakes of newcomers into TDD is that they often mistake the “Fail first” requirement with “Fail by testing something illogical”. For example, given a method requirement with this spec:

 

Int Sum(int a, int b) : returns the sum of the two numbers

 

They would write a failing test like this

 

[Test]

Public void Sum_AddsOneAndTwo()

{

     int result = Sum(1,2);

     Assert.AreEqual(4, result, “bad sum”);

}

 

While this might feel like a good way to make a failing test, it totally misses the idea of why we actually want to write a failing test. A failing test proves that there is something wrong with the production code. That is, the test should pass as is when the production code is fully done. As things stand with the test above – it is not logical and will fail even if the production code is complete. Making it pass requires changing the test itself – instead of making us change or add something to the production code. In short – this test does not reflect the end-reality like we would like it to be when the production code is complete, thus is not a good test.

 

On a more philosophical note

A good test in TDD will make us change the reality of the code to make it work, instead of reflecting the reality right now or reflecting a wrong reality (where 1+1 returns 0 just to fail the test).

We want the tests to reflect the reality like it should have been/we want it to be if the current requirement would have worked, then we make reality adjust to our needs.

 

Read: Tests should reflect required reality

Topic: The Roles of Role based development Previous Topic   Next Topic Topic: Podcasts- how many people listen?

Sponsored Links



Google
  Web Artima.com   

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