0

任何人都可以帮我在 grails(email:true) 中为电子邮件编写单元测试用例吗?

联系人姓名(最大尺寸:25) 联系人电子邮件(最大尺寸:50,电子邮件:真)

4

1 回答 1

0

Grails在文档中有一个关于单元测试的部分。检查“测试约束”。

例子:

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()
    }
}
于 2013-10-11T16:48:24.383 回答