我正在尝试让我的测试按顺序执行Specs2验收样式测试,但我没有运气。
override def is = {
"Template Project REST Specification" ^
p ^
"The server should" ^
"Respond with greeting on root path" ! serverRunning ^
p ^
"For CLIENT json objects" ^
"Return an empty list if there are no entities" ! getEmptyClientList ^
"Create a new entity" ! createClient ^
"Return a non-empty list if there some entities" ! getNonEmptyClientList ^
"Read existing" ! todo ^
"Update existing" ! todo ^
"Delete existing" ! todo ^
"Handle missing fields" ! todo ^
"Handle invalid fields" ! todo ^
"Return error if the entity does not exist" ! todo ^
end
}
运行测试时,createClient
测试会在getEmptyClientList
测试有机会执行之前继续创建新的客户端元素。
如果我在getEmptyClientList
测试之前添加了一大堆createClient
测试,那么除了最后一个之外的所有测试都会在调用createClient
之前执行。但createClient
将始终击败最后一次getEmptyClientList
来电,导致失败。
如何强制它按顺序执行?使用Specs2单元测试样式,我只是在测试之前添加了sequential
关键字,一切都很好。
答案 0 :(得分:2)
在验收规范中,sequential
参数可以在规范的开头添加,如下所示:
def is = sequential ^
"Template Project REST Specification" ^
p ^
"The server should" ^
"Respond with greeting on root path" ! serverRunning ^
p ^
"For CLIENT json objects" ^
"Return an empty list if there are no entities" ! getEmptyClientList ^
"Create a new entity" ! createClient ^
"Return a non-empty list if there some entities" ! getNonEmptyClientList ^
"Read existing" ! todo ^
"Update existing" ! todo ^
"Delete existing" ! todo ^
"Handle missing fields" ! todo ^
"Handle invalid fields" ! todo ^
"Return error if the entity does not exist" ! todo ^
end
请注意,您不需要override
is
方法,也不需要大括号。