单元测试
package com.gtunes class Song { String title String artist Integer duration
static constraints = {
duration min: 1
} }
duration值最小值测试
void testMinimumDuration() { // 设置Song类进行验证测试. . . mockForConstraintsTests Song // 创建一个新的song实例 def song = new Song(title: 'Some Title', artist: 'Some Artist', duration: 0) // song验证不通过. . . assert !song.validate() // duration验证不通过. . . assert 'min' == song.errors['duration'] }