TDD: 4 questions that will help you create the simplest thing that could possibly work

My blog has moved. You can view this post at the following address: http://www.osherove.com/blog/2010/1/6/tdd-4-questions-that-will-help-you-create-the-simplest-thing.html
Published Wednesday, January 06, 2010 4:36 PM by RoyOsherove
Filed under: , ,

Comments

# Twitter Trackbacks for TDD: 4 questions that will help you create the simplest thing that could possibly work - ISerializable - Roy [asp.net] on Topsy.com

Pingback from  Twitter Trackbacks for                 TDD: 4 questions that will help you create the simplest thing that could possibly work - ISerializable - Roy         [asp.net]        on Topsy.com

Wednesday, January 06, 2010 4:52 PM by J.R. Garcia

# re: TDD: 4 questions that will help you create the simplest thing that could possibly work

That's not more readable to me. Now it's confusing. Your log shows that the "login is ok for testuser" before it checks to see if it's ok. I understand your reasoning for moving it, but in that instance your now causing problems with the log. If I go to look at the log, I'll see that the login was ok, when it may or may not have been.

Wednesday, January 06, 2010 4:54 PM by Michael Stum

# re: TDD: 4 questions that will help you create the simplest thing that could possibly work

"Do we really need a double test with two different values? I’m partial to this."

So am I, but in most Test Frameworks this doesn't require you to write a separate test (i.e. xUnit.net has Theory/InlineData for that)

Wednesday, January 06, 2010 5:04 PM by RoyOsherove

# re: TDD: 4 questions that will help you create the simplest thing that could possibly work

Michael:

putting it up there is not a FINAL solution. it is an increment of the full solution. it is there to force me to create a test that proves it should *not* be there, for all the reasons you mention.

it *should* stand out like a sore thumb, but the only way to cure that pain is with a test.

Wednesday, January 06, 2010 5:21 PM by Liam

# re: TDD: 4 questions that will help you create the simplest thing that could possibly work

The simplest iteration possible to pass a test is something I sometimes fall fowl of myself. Preforming Katas helped to illustrate this point to me as Mark Needham also pointed out whilst attempting your String Calc Kata www.markhneedham.com/.../roy-osheroves-tdd-kata-my-first-attempt

Although I would think to move the log execution to where above the if statement, unless the first test was with bad data. Generally I would write tests with bad data after a test with good, yet I see your point.

Wednesday, January 06, 2010 5:29 PM by Michael Stum

# re: TDD: 4 questions that will help you create the simplest thing that could possibly work

You actually wanted to reply to J.R. Garcia :)

My 2 cents: Now that you moved the logger to the top, you can write another test that verfies the logger is NOT called if the login is not OK - you've just successfully added another failing test to your arsenal, which you can then refactor with confidence.

Wednesday, January 06, 2010 5:38 PM by Svish

# re: TDD: 4 questions that will help you create the simplest thing that could possibly work

Shorter? Yes

public bool IsLoginOk(string user, string password)

{

 log.Write("login ok for user: testuser");

 return m_users[user] != null && m_users[user] == pasword;

}

would have to switch it back when you want to just log when login is ok though... but still. Shorter == yes :p

# Beginners stupid question… – UK-Muscle Body Building Community … | Bodybuilding Fitness Wisdom

Pingback from  Beginners stupid question… – UK-Muscle Body Building Community … | Bodybuilding Fitness Wisdom

Thursday, January 07, 2010 4:26 AM by The Morning Brew - Chris Alcock » The Morning Brew #512

# The Morning Brew - Chris Alcock » The Morning Brew #512

Pingback from  The Morning Brew - Chris Alcock  » The Morning Brew #512

# TDD: 4 questions that will help you create the simplest thing that could possibly work – ISerializable – Roy Osherove's Blog

Pingback from  TDD: 4 questions that will help you create the simplest thing that could possibly work – ISerializable – Roy Osherove's Blog

Thursday, January 07, 2010 10:39 AM by nico

# re: TDD: 4 questions that will help you create the simplest thing that could possibly work

excellent advice, thanks a lot!

Thursday, January 07, 2010 12:23 PM by J.R. Garcia

# re: TDD: 4 questions that will help you create the simplest thing that could possibly work

Roy:

Ok. Then we can completely agree. I think those 4 questions are great

Thursday, January 07, 2010 1:24 PM by Bill Sorensen

# re: TDD: 4 questions that will help you create the simplest thing that could possibly work

You might want to consider discussing the "refactor" in "red-green-refactor" to avoid confusing readers. After a test passes the next step is to refactor to remove duplication.

Friday, January 08, 2010 5:01 AM by Most Tweeted Articles by Agile Development Experts

# Most Tweeted Articles by Agile Development Experts

Pingback from  Most Tweeted Articles by Agile Development Experts

Sunday, January 10, 2010 8:26 PM by Ramon Leon

# re: TDD: 4 questions that will help you create the simplest thing that could possibly work

> (in tdd you can only change production code functionality when you have a failing test)!

That's not at all true.  Anytime all tests are passing it's always OK to refactor to improve the design which would include simplifying the solution.

I don't think your example was very good, had you done the simplest thing that could possibly work, you'd never have to go back and try to hard code something because you'd have hard coded it immediately to pass the first test.  

DTSTTCPW is about making the smallest change possible to make a failing test pass, that's all.  It doesn't apply to the refactoring stage where you're trying to make the code cleaner or improve the design.  It only applies to the make the failing test pass stage.

Monday, January 11, 2010 8:17 AM by Me

# re: TDD: 4 questions that will help you create the simplest thing that could possibly work

What about using a randomly generated user name in the unit test? Then you will be forced not to hard code the user name.

Monday, January 11, 2010 11:40 AM by Lee Brandt

# re: TDD: 4 questions that will help you create the simplest thing that could possibly work

Great post, good advice.

Thanks,

Lee

Wednesday, January 13, 2010 10:05 AM by Christopher Atkins

# re: TDD: 4 questions that will help you create the simplest thing that could possibly work

@Ramon

The didactic cause of this post is served well by the example.  The point is to help people (Roy's students specifically) characterize "the simplest thing that could possibly work".

@Roy

Do the questions you ask at the end of your post about the efficacy of the new tests point us to refactoring the original test, i.e. Should_Log_After_Successful_Login, to enforce a strict ordering of the expectations?  This would then might force a refactoring to e.g. a loggedin event.  In truth the original test doesn't really specify the behavior properly, does it?