Blog Archives

Unit Testing Freemarker Templates

I encountered a defect arising from a Freemarker template, fixed it, and then wanted a better way of testing it than firing up the app and checking the effects visually in a browser. Ignoring for a minute whether or not

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

Hamcrest JSON Matchers

I couldn’t find a Hamcrest matcher for JSON that worked how I wanted, so I adapted the JsonAssert library. This allows you to use dot notation to specify the path to a node in a json string, and use any

Posted in Clean Test Code, Hamcrest

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