1

我试图让我的测试通过 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在测试之前添加了关键字,一切都会好起来的。

4

1 回答 1

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

请注意,您不需要overrideis方法,也不需要花括号。

于 2012-11-16T22:18:31.737 回答