I have used manually written as well as Grails generated Unit tests for this command object:
package myapp
@grails.validation.Validateable
class
You are using the validate
method incorrectly. You never set the field on the class, so the field is null, not blank. Try changing your test as follows:
void testSomething() {
SearchCommand commandUnderTest = new SearchCommand()
commandUnderTest.basisBuild = ""
assertFalse commandUnderTest.validate()
assertEquals 'blank', commandUnderTest.errors['basisBuild']
}
Edit: There is also a grails bug when testing command classes that use the @Validatable
annotation. There are some workarounds in the bug commentary.