所以我们有一个宁静的服务,我们想在grails中使用restclient进行测试。如何在Grails中设置功能测试的测试数据?
测试代码应该是这样的......
class MyControllerSpec extends Specification {
def setup() {
this.dbEntity = new DbEntity("someid123").save();
}
void "Test entity GET"{
given:
RestBuilder rest = new RestBuilder()
when: "The DB entity service is hit"
RestResponse restResponse = rest.post("http://localhost:8080/api/someentity/$id");
then: "A 200 error is sent"
restResponse.status == 200
}
我遇到的问题是设置方法上.save炸毁()因为没有休眠会话。如何在运行测试之前操作我的数据库?
您是否尝试添加测试“setup:”block? – Koloritnij