如何执行仅匹配正则表达式的测试?
在 sbt 0.10.1 中,我经常使用 test-only
来缩小测试数量。
sbt> test-only com.example.MySpec
但是,我想缩小范围,以便只运行名称/描述与正则表达式匹配的测试。是否有一些语法可以实现类似的效果?
sbt> test-only .*someRexExp.*
In sbt 0.10.1, I frequently use test-only
to narrow down the number of my tests.
sbt> test-only com.example.MySpec
However, I want to narrow down such that I only run tests whose name/description matches a regular expression. Is there some syntax to achieve something like this?
sbt> test-only .*someRexExp.*
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
testOnly
不支持完整的正则表达式。但是,支持通配符。此处仅专门解释星号
*
,而不是句点。这将选择以com.example.
开头并以Spec
结尾的所有测试。或者只是所有测试
Spec
:testOnly
和其他测试信息记录在此处:http://www.scala-sbt.org/release/docs/Detailed-Topics/TestingFull regular expressions are not supported by
testOnly
. Wildcards are supported, however.Only the asterisk
*
is interpreted specially here and not the periods. This will select all tests beginning withcom.example.
and ending withSpec
.Or just all test
Spec
s:testOnly
and other testing information is documented here: http://www.scala-sbt.org/release/docs/Detailed-Topics/Testing您可以使用 特定于框架的运行程序参数。 ScalaTest 支持使用
-z
参数进行子字符串匹配:这将运行所有测试正如您所直觉的那样,在其名称中添加“insert”,然后仅以
TreeSpec
结尾的套件中的匹配案例。您还可以使用-n TagName
和-l TagName
分别包含或排除 ScalaTest 标记支持中的标记,并使用-t
进行匹配准确的测试名称。Specs2 支持完整的 Java 常规带有
-ex
参数的表达式:-include
和-exclude
支持 Spec2 的标记功能。请参阅内联链接以获取运行程序支持的参数的完整列表。这些似乎仅适用于
testOnly
sbt 命令,而不适用于test
。You can match on test cases by their name (instead of or in addition to suite class names) by using framework-specific runner arguments. ScalaTest supports a substring match with the
-z
argument:This runs all tests with "insert" in their name, then only the matching cases within suites ending in
TreeSpec
, as you would intuit. You can also use-n TagName
and-l TagName
to include or exclude, respectively, tags from ScalaTest's tagging support, and-t
to match an exact test name.Specs2 supports full Java regular expressions with an
-ex
argument:-include
and-exclude
support Spec2's tagging features.See the inline links for full lists of arguments that the runners support. These appear to only work with the
testOnly
sbt command and nottest
.