【发布时间】:2016-06-06 15:29:28
【问题描述】:
我想知道如何构建一个域类对象的世界以在我的单元测试中使用。最好的方法是什么?
说这是我的代码,ServiceX:
List<Course> getAllCoursesByType(String type) {
List<Course> list = Course.findAllByType(type)
list
}
这是对 ServiceX 的测试:
import grails.buildtestdata.mixin.Build
import grails.test.mixin.TestFor
import grails.test.mixin.Mock
import spock.lang.Specification
@TestFor(ServiceX)
class ServiceXSpec extends Specification {
void "get all open courses"() {
given:
String type = "open"
when:
def list = service.getAllCoursesByType(type)
then:
list.size() == 4
}
}
我如何“预先填充”test-db(内存)播种我实际上在列表中有 4 个这样的对象?
【问题讨论】:
标签: unit-testing grails grails-orm spock grails-3.0