使用specs2指定测试顺序(scala/play框架)

ter*_*mux 1 scala specs2

我目前正在使用Specs2库为Scala Play应用程序编写一组测试.

我在编译过程中遇到了一些堆栈溢出错误,因为测试字符串太长,所以我将它拆分成几个类.

问题是测试是使用多线程进程同时运行的.我需要指定那些测试的顺序.有没有办法做到这一点?问候.

Jac*_*ack 5

您可以通过添加sequential到规范中指定测试必须按顺序执行.

如果您正在使用单元样式测试,请将语句sequential放在测试上方的一行中(从specs docs借用的示例):

  import org.specs2.mutable._

  class HelloWorldSpec extends Specification {

    sequential

    "The 'Hello world' string" should {
      "contain 11 characters" in {
        "Hello world" must have size(11)
      }
      "start with 'Hello'" in {
        "Hello world" must startWith("Hello")
      }
      "end with 'world'" in {
        "Hello world" must endWith("world")
      }
    }
  }
Run Code Online (Sandbox Code Playgroud)

如果您正在使用验收样式测试,只需在定义中添加顺序 is

 import org.specs2._

  class HelloWorldSpec extends Specification { def is =

    sequential                                                      ^
    "This is a specification to check the 'Hello world' string"     ^
                                                                    p^
    "The 'Hello world' string should"                               ^
      "contain 11 characters"                                       ! e1^
      "start with 'Hello'"                                          ! e2^
      "end with 'world'"                                            ! e3^
                                                                    end

    def e1 = "Hello world" must have size(11)
    def e2 = "Hello world" must startWith("Hello")
    def e3 = "Hello world" must endWith("world")
  }
Run Code Online (Sandbox Code Playgroud)

作为旁注,您可能会从软件中的错误中获得堆栈溢出错误,而不是测试太长.