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...

6 comments:

J.Ord.An said...

Congratulazioni!

ps
sei un pazzo! :-)

Nathan said...
This comment has been removed by the author.
Nathan said...

Excellently written article and information was helpful. Please keep it up thank for sharing.
Business Analytics Course in Chennai

Tech Institute said...

Very informative message! There is so much information here that can help me thank you for sharing
Data Analytics Course in Lucknow

Bhuvankumar said...
This comment has been removed by the author.
John Albert said...

Your own devotion to getting the arrangement all through had become especially beneficial and has empowered customary individuals very much like me to accomplish their interests. Edgerunner David jacket