2013-10-11 2 views

답변

0

Grails는이 section in the documentation about unit testing 있습니다. "Testing Constraints"를 확인하십시오.

예 :

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() 
    } 
} 
관련 문제