任何人都可以帮我编写grails电子邮件的单元测试用例(email:true)吗?
CONTACTNAME(MAXSIZE:25) contactEmail(maxSize:50,email:true)
答案 0 :(得分:0)
Grails有一个section in the documentation about unit testing。检查“测试约束”。
示例:
class Person {
String name
static constraints = {
name matches: /[A-Z].*/
}
}
import grails.test.mixin.TestFor
import spock.lang.Specification
@TestFor(Person)
class PersonSpec extends Specification {
void "Test that name must begin with an upper case letter"() {
when: 'the name begins with a lower letter'
def p = new Person(name: 'jeff')
then: 'validation should fail'
!p.validate()
when: 'the name begins with an upper case letter'
p = new Person(name: 'Jeff')
then: 'validation should pass'
p.validate()
}
}