【发布时间】:2012-11-19 16:37:00
【问题描述】:
我目前正在使用 Specs2 库为 Scala Play 应用程序编写一组测试。
由于测试字符串太长,我在编译过程中遇到了一些堆栈溢出错误,所以我把它分成了几个类。
问题在于测试是使用多线程进程同时运行的。我需要指定这些测试的顺序。有没有办法做到这一点?问候。
【问题讨论】:
-
欢迎来到stackoverflow。只要您的代码的相关部分,请考虑发布您尝试过的内容。否则没人能帮你
我目前正在使用 Specs2 库为 Scala Play 应用程序编写一组测试。
由于测试字符串太长,我在编译过程中遇到了一些堆栈溢出错误,所以我把它分成了几个类。
问题在于测试是使用多线程进程同时运行的。我需要指定这些测试的顺序。有没有办法做到这一点?问候。
【问题讨论】:
您可以通过在规范中添加sequential 来指定测试必须按顺序执行。
如果您使用单元样式测试,请将语句 sequential 放在测试上方的一行中 (examples borrowed from 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")
}
}
}
如果您使用验收风格测试,只需在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")
}
附带说明,您可能会从软件中的错误中得到堆栈溢出错误,而不是测试太长。
【讨论】:
class UsersSpec extends Specification with BeforeAll with Before {
def is = sequential ^ s2"""
We can create in the database
create a user $create
list all users $list
"""
import DB._
def create = {
val id = db.createUser("me")
db.getUser(id).name must_== "me"
}
def list = {
List("me", "you").foreach(db.createUser)
db.listAllUsers.map(_.name).toSet must_== Set("me", "you")
}
// create a database before running anything
def beforeAll = createDatabase(databaseUrl)
// remove all data before running an example
def before = cleanDatabase(databaseUrl)
希望对你有帮助!
【讨论】: