Wednesday, May 6, 2009

Note to self: How to do integration testing

When writing integration tests in Grails. First construct the data objects, then save them (and get error messages when consistency rules are violated), then finally construct connections and test integrations.

Just a practical note to all Grails developers

As you all know, testing is good for you. But you know, in Grails it is not just good for you; You absolutely positively need to add tests for everything and you need to do it up front. No exceptions accepted and severe punishment metered out to those who fail to follow this commandment.

Why? Well Grails, wonderful as is, when running in production mode probablyhas the least intelligible error messages in the known universe. Usually (or at least usually in my case) they consist of a mile-long stacktrace containing references to null pointers and bad servlet contexts and other things that will give you exactly zero clue about what you have done wrong.

The unit and integration tests on the other hand will give you intelligible error messages, so for that reason alone you should write tests like it was your religious duty to do so, which it probably should be anyway, so just do it.