NEO

蜀道难,难于上青天!

导航

Grails指南摘要-307-测试领域类

Posted on 2013-06-04 22:28  页面载入出错  阅读(162)  评论(0编辑  收藏  举报

单元测试

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']
    }