[英]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.