Making Good Software

A blog by Alberto G (Alberto Gutierrez)

Written by Alberto Gutierrez

August 3rd, 2009 at 4:45 pm

Fitnesse and xUnit, the perfect TDD marriage.

without comments

I am a convinced TDD developer, TDD makes you more productive and helps you to create robust and simple code, but it has a flaw, TDD doesn’t help you deciding where to start coding, you have to decide what test you want to write first, and them you keep building from there, this may lead you to a dangerous path where you are actually going forward, but you are taking the wrong direction.

Fitnesse can help you to overcome this problem, Fitnesse is a testing tool that helps you to write acceptance tests as tables in a wiki page. Practically it means that you can first write the tests that will wire all the functionality you want to implement.

Creating the fitnesse test.

The following is a screen capture of a simple acceptance test created in fitnesse to test a chess pawn movement. See that Fitnesse allows you to write tests in such way that they should be self explanatory.

fitnesseFinal

Creating the xUnit test for the fitnesse test and using TDD from there.

Now that we have the acceptance test created and implemented, we can write a xUnit test for it and start applying TDD (note that the implementation details for the fitnesse test are outside of the scope of this post, you can check the fitnesse documentation for reference).

At this stage we will have a failing test which we can make pass very easily using the simplest solution possible, then we can extend the fitnesse test, for example we can add a second case where we try to move two white pawns in a row so that the second pawn movement should be illegal (is the black player turn). We always repeat the same steps until all the desired functionality is implemented: write an acceptance test in fitnesse – write a xUnit test for that acceptance test – apply TDD from there.

Advantages of using Fitnesse.

  1. It gives you an starting point to code from.
  2. It sets a clear goal of what you need to implement.
  3. When you finish your implementation it validates that it works end to end.
  4. It provides a friendly UI so that even non technical people can write their own test cases.
Easy AdSense by Unreal

Related posts:

  1. Book review: xUnit Test Patterns
  2. How to write good tests. Top 5 considerations to build software without defects.
  3. Forget about requirements, Software Development is all about inputs, outputs and actions.
  4. Java and tree data structures.
  5. How to write readable code? 5 Tips to improve your code readability.

Leave a Reply