0
我試圖寫我的域類的單元測試來測試約束,但我得到了意想不到的結果。這裏是我的域類:Grails:單元測試域類約束給出了錯誤的結果
class Student {
String firstName
String lastName
static constraints = {
firstName blank:false,minSize:2,maxSize:20,validator: { val, obj ->
def similarUser = Student.findByFirstNameIlikeAndLastNameIlike(obj.firstName, obj.lastName)
if(!similarUser || obj.id == similarUser.id){
return ['Student.invalid.unique.message']
}
}
lastName blank:false, minSize:2,maxSize:20
}
}
,這裏是我的單元測試:
@TestFor(Student)
@Mock(Student)
class StudentTests {
def st
@Before
void setUp(){
mockForConstraintsTests(Student)
st=new Student(firstName:"FerasO",lastName:"Ahmad")
}
@Test
void testMinSize() {
assertTrue student.validate() // I guess this should return true but It returns false
}
}
什麼是與回事?我怎麼解決它?
感謝,