Monthly Archives: April 2014

Great Expectations

What’s the best way to handle expected exceptions in JUnit? If you want to inspect the contents of the exception and make assertions against it then there is only one clean way; Use the ExpectedException JUnit Rule. I’ve seen it

Posted in Clean Test Code, Hamcrest, JUnit, JUnit Rule

Reusable Test Utility Code and Maven

I often see almost identical bits of code copied and pasted in test classes spread throughout different packages, even different modules. Sometimes someone will bother to create a reusable utility class that is called from different tests, but then someone

Posted in Clean Test Code, Maven

JodaTime and JUnit

JUnit Rules are powerful things. There are all sorts of things you can do with a Rule that makes test code cleaner and less error-prone. Because a Rule wraps the test method, it’s really useful for things that need both

Posted in Clean Test Code, JUnit, JUnit Rule

Flexible Mocking

Unit tests, in particular the assertions within, should be no more and no less specific than they need to be. Make a test too loose, and it will be possible for someone to make changes to the code in a

Posted in Clean Test Code, EasyMock