12 Nov 2008

Why you should use JUnit4

I've been using JUnit 4 from time to time but never really understood the benefit moving from version 3 to version 4.

That's because I never took time to take a look at new features :o

Don't be like me ;) Just take a look at this article: "Junit 4 in 60 seconds"

You will discover annotations like:
  • Better Exception Handling with @Test(expected = ArithmeticException.class)
  • @Ignore("Not Ready to Run")
  • @Test(timeout = 1000)

Small enhancements making testing easier and clearer!

1 comment:

Benjamin Cabé said...

And since JUnit 4.4, there are advanced assertions like:

assertThat(x, is(3));
assertThat(x, is(not(4)));
assertThat(responseString, either(containsString("color")).or(containsString("colour")));
assertThat(myList, hasItem("3"));

:-)