Thursday, May 2, 2013

I broke a build... let's celebrate!

Some three years ago I wrote a small test for a very particular factory: it worked pretty well, even if I've never really liked the constraints imposed by the requirements about the exception that is expected to be thrown.

Yesterday, not quite unexpectedly, the build was broken.

Obviously this is not really a unit test, as it depends on real data, so I'd call it more an integration test. Anyway, the data changed and the test failed, thus breaking the build. Normally I wouldn't be so happy. Yet in this case, even if it might be an antipattern (it clearly is), I think I won't change the test to be independent from data, but change the test instead:

@Test(expected=IllegalArgumentException.class)
public void makeBaby() {
  Family family = moz.getFamily();
  assertEquals(3, family.getChildren().size());
  BabyFactory factory = family.getWife();
  Baby babyboy = factory.makeBabyBoy("Ethan");
  assertNotNull(babyboy);
  family.addChild(babyboy);
  assertEquals(4, family.getChildren().size());

  boss.askForRaise(moz);
}

Now I'm only waiting for the requirements to change so that I can remove the exception...

1 comment:

J.Ord.An said...

Congratulazioni!

ps
sei un pazzo! :-)