我正在尝试对 Grails 域类执行基本单元测试。
这是域类:
class User {
String username
String password
String email
static constraints = {
username size: 4..15, blank: false, unique: true
password size: 5..15, password: true, blank: false
email email: true, blank: false
}
}
这是单元测试类:
@TestFor(User)
class UserTests {
void testCreateUser() {
def u = new User(username:"ab")
assertFalse "There should be errors", u.validate()
assertTrue "Should be errors here", u.hasErrors()
}
}
username
受限于从 4 到 15 的大小。但是,当我运行grails test-app
上述测试成功时。我不明白为什么约束没有导致它失败。