使用Specs2验收样式测试强制执行顺序

时间:2012-11-16 14:53:56

标签: scala specs2

我正在尝试让我的测试按顺序执行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关键字,一切都很好。

1 个答案:

答案 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方法,也不需要大括号。

相关问题