[英]Running an individual test from a specification
Is there a way to run a specific test from a Specs 2 Specification
? 有没有一种方法可以运行来自Specs 2 Specification
的特定测试? eg If I have the following: 例如,如果我有以下内容:
class FooSpec extends Specification {
"foo" should {
"bar" in {
// ...
}
"baz" in {
// ...
}
}
}
I would like to have a way to run only FooSpec > "foo" > "bar"
(using some arbitrary notation here). 我想有一种方法只运行FooSpec > "foo" > "bar"
(在这里使用一些任意符号)。
You can use the ex
argument from sbt to run a specific example: 您可以使用sbt中的ex
参数来运行特定示例:
sbt> test-only *FooSpec* -- ex bar
You can also mix-in the org.specs2.mutable.Tags
trait and include a specific tag: 您还可以混入org.specs2.mutable.Tags
特性,并包括一个特定的标签:
sbt> test-only *FooSpec* -- include investigate
class FooSpec extends Specification with Tags {
"foo" should {
tag("investigate")
"bar" in {
// ...
}
"baz" in {
// ...
}
}
}
You can also just re-run the previously failed examples, whatever they are 您也可以重新运行先前失败的示例,无论它们是什么
sbt> test-only *FooSpec* -- was x
Finally, in the next 2.0 release (or using the latest 1.15-SNAPSHOT), you will be able to create a script.Specification
and use "auto-numbered example groups": 最后,在下一个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
There is however no way to specify, with a mutable Specification, that you want to run the example "foo" / "bar"
. 但是,无法使用可变的Specification来指定要运行示例"foo" / "bar"
。 This might be a feature to add in the future. 这可能是将来添加的功能。
You can choose the namespace of tests to be executed, but AFAIK there's no way to run a specific test from the sbt console
. 您可以选择要执行的测试的名称空间,但是AFAIK无法从sbt console
运行特定的测试。 You can do something like: 您可以执行以下操作:
sbt test:compile "test-only FooSpec.*"
, which runs the tests only from the FooSpec
namespace, but this selection is namespace based and not even that works properly. sbt test:compile "test-only FooSpec.*"
,它仅从FooSpec
命名空间运行测试,但是此选择基于命名空间,甚至不能正常工作。 This is the selection mechanism, but it somehow fails and always runs the entire set of tests found in your project. 这是选择机制,但是它某种程度上失败了,并且总是运行在项目中找到的整套测试。
Update 更新
From the official documentation : 从官方文档中 :
test-only
The test-only task accepts a whitespace separated list of test names to run. 仅测试任务接受由空格分隔的测试名称列表以运行。 For example: 例如:
test-only org.example.MyTest1 org.example.MyTest2
It supports wildcards as well: 它也支持通配符:
test-only org.example.*Slow org.example.MyTest1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.