0
任何人都可以幫我寫出grails(電子郵件:真)電子郵件的單元測試用例嗎?grails中電子郵件的單元測試用例(電子郵件:true)
聯繫人姓名(MAXSIZE:25) contactEmail(MAXSIZE:50,電子郵件:真)
任何人都可以幫我寫出grails(電子郵件:真)電子郵件的單元測試用例嗎?grails中電子郵件的單元測試用例(電子郵件:true)
聯繫人姓名(MAXSIZE:25) contactEmail(MAXSIZE:50,電子郵件:真)
的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()
}
}