March 12, 2007 - Testing Around the Edges

It's an interesting word, 'test'. It can mean so many things. Before XP came along it used to mean

find out whether something works correctly

The T in TDD doesn't quite capture that meaning (TDD is not about testing) and neither does the 'test' in acceptance test.

Most XP teams, before they declare a story 'done', like to do a little exploratory testing to make sure the code behaves sensibly in areas that may be under-specified. In other words, they test it.

My code doesn't really do much yet, so I am going generate some additional tests with JUnit Factory to see if it comes up with anything. JUnit Factory is designed to generate characterization tests but you can often get some insights by scanning through the tests that it generates.

I hit the generate tests button and, sure enough, the first test says:


public void testBowl() throws Throwable {
  Game game = new Game();
  game.bowl(100);
  assertFalse("game.isGameOver()", game.isGameOver());
}

Hmmm...bowl(100)...that's probably not right.

I look back over the rules and discover that nowhere in the international rules for tenpin bowling does it say how many pins there are. I guess it's implied in the name.

I asked the customer what to do if the lane machine says 100 pins were knocked down. He said to throw an IllegalArgumentException for now and we'll figure out how to deal with it when we interface with the lane machine. Here are some new acceptance tests:


  @Test(expected=IllegalArgumentException.class) 
  public void shouldThrowAnExceptionIfTooManyPins() {
    deliverBall(11);
  }

  @Test(expected=IllegalArgumentException.class) 
  public void shouldThrowAnExceptionIfPinCountIsNegative() {
    deliverBall(-1);
  }

I add a little defensive coding to make those pass and regenerate the JUnit Factory tests. Everything looks good now, so I'll move on to the next story.


Posted by Kevin Lawrence at March 12, 2007 12:37 PM


Trackback Pings

TrackBack URL for this entry:


Comments

Post a comment




Remember Me?