JUnit 4.4 now uses Theories, Assumptions and Hamcrest assertions...
Submitted by Antony Marcano on Sun, 22/07/2007 - 10:10.
JUnit
I was pleased to see JUnit 4.4incorporate hamcrest assertions.
Hamcrest assertions emerged from JMock and is a 'literate' or 'fluent' API for assertions.
assertThat(x, is(3));
assertThat(x, is(not(4)));
assertThat(responseString,
either(containsString("color")).or(containsString("colour")));
assertThat(myList, hasItem("3"));
-JUnit 4.4 Release Notes
Separating JMock's assertion framework into Hamcrest made things better for a lot of us who were importing JMock into our unit tests, even if all we wanted were the assertions capabilities... it also inspired new applications of it's capabilities, not least, simplifying iterators:
List numbers = Arrays.asList(-1, 0, 1, 2);
print("detect int: " + detect(numbers, greaterThan(0)));
Being able to import only hamcrest, rather than all of JMock was a nice touch... now, it's all built into JUnit and has enabled some interesting new features... Assumptions and Theories.
I've seen a few objections to this style of programming and, for those who don't like it, the original JUnit assertions are still there. If, like me, you find that the hamcrest style helps your unit-tests to be more communicative (as executable design specifications - `a la TDD), hamcrest assertions are now available straight out of the JUnit box.
Nice work!