gpt4 book ai didi

unit-testing - 根据规范运行单个测试

转载 作者:行者123 更新时间:2023-12-04 05:10:49 24 4
gpt4 key购买 nike

有没有办法从 Specs 2 Specification 运行特定测试?例如如果我有以下内容:

class FooSpec extends Specification {
"foo" should {
"bar" in {
// ...
}

"baz" in {
// ...
}
}
}

我想有一种方法只运行 FooSpec > "foo"> "bar"(在这里使用一些任意的符号)。

最佳答案

您可以使用 sbt 的 ex 参数来运行特定示例:

sbt> test-only *FooSpec* -- ex bar

您还可以混入 org.specs2.mutable.Tags 特征并包含特定标签:

sbt> test-only *FooSpec* -- include investigate

class FooSpec extends Specification with Tags {
"foo" should {
tag("investigate")
"bar" in {
// ...
}
"baz" in {
// ...
}
}
}

您也可以重新运行之前失败的示例,无论它们是什么

sbt> test-only *FooSpec* -- was x

最后,在下一个 2.0 版本中(或使用最新的 1.15-SNAPSHOT),您将能够创建一个 script.Specification 并使用“自动编号示例组”:

import specification._

/**
* This kind of specification has a strict separation between the text
* and the example code
*/
class FooSpec extends script.Specification with Groups { def is = s2"""
This is a specification for FOO

First of all, it must do foo
+ with bar
+ with baz

"""

"foo" - new group {
eg := "bar" must beOk
eg := "baz" must beOk
}
}

// execute all the examples in the first group
sbt> test-only *FooSpec* -- include g1

// execute the first example in the first group
sbt> test-only *FooSpec* -- include g1.e1

然而,无法使用可变规范来指定您想要运行示例 "foo"/"bar"。这可能是将来要添加的功能。

关于unit-testing - 根据规范运行单个测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16437654/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com