我对 grails 中的这个字段有这个约束:
businessNumber(matches: '([0-9A-Z]*9)RA([0-9A-Z]*4)', maxSize: 15)
我正在设置 maxSize 约束,以便 grails 在 html 视图上嵌入一个 maxlength 属性。我对如下所示的约束进行了单元测试:
void testBusinessNumberExceedMaxSize(){
mockChildrenSpecialAllowancesForm.setBusinessNumber("F%G&Hy934F4G6H%55")
assertFalse (mockChildrenSpecialAllowancesForm.validate())
assertEquals ("maxSize",mockChildrenSpecialAllowancesForm.errors.businessNumber)
assertEquals (2, mockChildrenSpecialAllowancesForm.errors.getErrorCount())
}
然后,它会生成此故障:
testBusinessNumberExceedMaxSize(com.ass.socialservicescm.ChildrenSpecialAllowancesTests)
| org.junit.ComparisonFailure: expected:<ma[xSize]> but was:<ma[tches]>
at org.junit.Assert.assertEquals(Assert.java:125)
at org.junit.Assert.assertEquals(Assert.java:147)
at com.ass.socialservicescm.ChildrenSpecialAllowancesTests.testBusinessNumberExceedMaxSize(ChildrenSpecialAllowancesTests.groovy:177)
我假设它违反了 2 个约束(因为我的错误计数是 2),一个是 maxSize,另一个是匹配项。但是我如何为 maxSize 约束做一个 assertEquals 呢?
注意:我正在使用 grails 2.0.0