有没有办法链接两个任意的 specs2 测试(在 Scala 中)?
Is there a way to chain two arbitrary specs2 tests (in Scala)?
我时常 运行 遇到这样一种情况,我需要绝对确保一个测试在另一个测试之前执行(成功)。
例如:
"The SecurityManager" should {
"make sure an administrative user exists" in new WithApplication with GPAuthenticationTestUtility {
checkPrerequisiteAccounts(prerequisiteAccounts)
}
"get an account id from a token" in new WithApplication with GPAuthenticationTestUtility {
val token = authenticate(prerequisiteAccounts.head)
token.isSuccess must beTrue
myId = GPSecurityController.getAccountId(token.get)
myId != None must beTrue
myId.get.toInt > 0 must beTrue
}
如果管理员用户不存在,第一个测试将创建它。第二个测试使用该帐户执行测试。
我知道我可以在 specs2 中进行 Before/After 处理(尽管我从未做过)。但我真的不希望在每次测试之前 checkPrerequisiteAccounts
到 运行,就在第一个测试执行之前......有点像 "before you start doing anything at all, do this one thing..."
任何人都知道是否有办法将特定测试标记为 "do first" 或 "do before anything else?"
您可以在测试之间添加一个 "Step" 以强制执行一些顺序性:
"make sure an administrative user exists" in ok
step("admin is created".pp)
"get an account id from a token" in ok
您还可以将顺序添加到规范中,例如顺序执行测试。
class MySpec extends mutable.Specification {
sequential
// rest follows
behaviour one
behaviour two
}
我时常 运行 遇到这样一种情况,我需要绝对确保一个测试在另一个测试之前执行(成功)。
例如:
"The SecurityManager" should {
"make sure an administrative user exists" in new WithApplication with GPAuthenticationTestUtility {
checkPrerequisiteAccounts(prerequisiteAccounts)
}
"get an account id from a token" in new WithApplication with GPAuthenticationTestUtility {
val token = authenticate(prerequisiteAccounts.head)
token.isSuccess must beTrue
myId = GPSecurityController.getAccountId(token.get)
myId != None must beTrue
myId.get.toInt > 0 must beTrue
}
如果管理员用户不存在,第一个测试将创建它。第二个测试使用该帐户执行测试。
我知道我可以在 specs2 中进行 Before/After 处理(尽管我从未做过)。但我真的不希望在每次测试之前 checkPrerequisiteAccounts
到 运行,就在第一个测试执行之前......有点像 "before you start doing anything at all, do this one thing..."
任何人都知道是否有办法将特定测试标记为 "do first" 或 "do before anything else?"
您可以在测试之间添加一个 "Step" 以强制执行一些顺序性:
"make sure an administrative user exists" in ok
step("admin is created".pp)
"get an account id from a token" in ok
您还可以将顺序添加到规范中,例如顺序执行测试。
class MySpec extends mutable.Specification {
sequential
// rest follows
behaviour one
behaviour two
}