My general rule is to test what I write. Therefore, if I write custom methods (or closures) then I'll unit test those. This rule also means I'll test constraints since I've written the constraints. For that I use mockForConstraintsTests() method in GrailsUnitTestCase.
An example constraints block:
static constraints = {
location(blank:true, nullable:true)
make(blank:false, nullable:false)
name(blank:false, nullable:false)
serviceTag(nullable:true)
purchaseDate(blank:false, nullable:false)
checkedDate(blank:false, nullable:false)
warrantyExpirationDate(nullable:true)
notes(blank:true, nullable:true)
}
I would have the following constraints unit test:
void test_null_constraints_are_checked() {
mockForConstraintsTests(Hardware)
def hardware = new Hardware()
assertFalse hardware.validate()
assertEquals 4, hardware.errors.getFieldErrorCount()
assertEquals "nullable", hardware.errors["name"]
assertEquals "nullable", hardware.errors["checkedDate"]
assertEquals "nullable", hardware.errors["purchaseDate"]
assertEquals "nullable", hardware.errors["make"]
}
This will catch any typos on my constraints right away.
I don't test saves, creates, updates, deletes at the domain; if these fail then I have bigger problems!