It can’t be emphasized enough that after correctness, comprehensibility is the most important feature of test code. Rob Fletcher, “Spock: Up and Running” Truth.
It can’t be emphasized enough that after correctness, comprehensibility is the most important feature of test code. Rob Fletcher, “Spock: Up and Running” Truth.
Just heard an interesting talk by Kevin Rutherford at Agile Manchester about connascence and how it can be used as a guide during the refactor part of the TDD cycle (red-green-refactor). “Connascence of value”, for example, means that the test code…
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…
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…
Some level of tests, let’s call it integration testing because it’s not technically unit testing, often need to load resources like XML samples from the file system. A talented developer I worked with recently, came up with this nice use…
It is still surprisingly common to see test methods named “test” followed by the name of a some method that’s going to be called. Sometimes you get a few words mentioning some other internal detail, like This sucks. I’m amazed…
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…
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…
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…
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…