繁体   English   中英

Grails Spock单元测试不断失败?

[英]Grails Spock unit test keeps failing?

我目前正在尝试使用Spock框架对Grails中的域模型约束进行单元测试,但遇到了一些问题。 因此,我具有以下受各种约束的领域模型:

class profile {

    String phoneNo
    String userName

    static belongsTo = [group:Group]

    static constraints = {
        phoneNo(blank:false, maxsize:14, matches:"44[0-9]{10}")
    }

}

然后,我进行了此测试,该测试应能够一次测试每个字段约束并返回预期结果:

@Unroll("test profile all constraints #field is #error")
    def "test profile all constraints"() {
        when:
        def newObj = new Profile("$field": val)

        then:
        validateConstraints(newObj, field, error)

        where:
        error                  | field        | val
        'blank'                | 'phoneNo'    | '447897654321'
        'maxSize'              | 'phoneNo'    | '123456789012'
        'matches'              | 'phoneNo'    | getPhoneNumber(true)

    }

但是,当我运行测试时,请说出“电话号码字段”的“最大大小”约束,并将其传递的值小于可用的最大大小,我希望该测试能够通过,但失败了,实际上所有测试都失败了,我不确定为什么我是使用此框架的新手。 我真的很感谢这方面的帮助。

提前致谢

我现在设法解决了这个问题。

问题与约束的模拟有关,我在为要执行的测试模拟错误的约束。

谢谢您的帮助

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM