我是Groovy和Grails的新手.由于空字符串被转换为null,因此要测试持久化的域对象的Spock测试失败.这是代码.域对象,
class Todo {
String name
Date createdDate
String priority
String status
static constraints = {
priority blank: true
}
}
Run Code Online (Sandbox Code Playgroud)
Spock规范,
@TestFor(Todo)
class TodoSpec extends Specification {
void "test persist"() {
when:
new Todo(name: 't1', createdDate: new Date(), priority: "1", status: 'ok').save()
new Todo(name: 't2', createdDate: new Date(), priority: '', status: 'ok').save()
then:
Todo.list().size() == 2
}
}
Run Code Online (Sandbox Code Playgroud)
结果grails test-app是
Todo.list().size() == 2
| | |
| 1 false
[collab.todo.Todo : 1]
at collab.todo.TodoSpec.test persist(TodoSpec.groovy:18)
Run Code Online (Sandbox Code Playgroud)
我找到的空字符串'' …