scala 如何执行仅匹配正则表达式的测试?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6997730/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to execute tests that match a regular expression only?
提问by tobym
In sbt 0.10.1, I frequently use test-onlyto narrow down the number of my tests.
在 sbt 0.10.1 中,我经常使用test-only来缩小我的测试数量。
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.*
回答by Mark Harrah
Full regular expressions are not supported by testOnly. Wildcards are supported, however.
不支持完整的正则表达式testOnly。但是,支持通配符。
sbt> testOnly com.example.*Spec
Only the asterisk *is interpreted specially here and not the periods. This will select all tests beginning with com.example.and ending with Spec.
*此处仅对星号进行特殊解释,而不对句点进行特殊解释。这将选择以 开头com.example.和结尾的所有测试Spec。
Or just all test Specs:
或者只是所有测试Spec:
sbt> testOnly *Spec
testOnlyand other testing information is documented here: http://www.scala-sbt.org/release/docs/Detailed-Topics/Testing
testOnly和其他测试信息记录在这里:http: //www.scala-sbt.org/release/docs/Detailed-Topics/Testing
回答by ches
You can match on test casesby their name (instead of or in addition to suite class names) by using framework-specific runner arguments. ScalaTest supports a substring matchwith the -zargument:
您可以匹配测试情况下通过使用他们的名字(而不是或除了套件的类名)特定于框架的亚军参数。ScalaTest支持与-z参数的子字符串匹配:
> testOnly -- -z insert
> testOnly *TreeSpec -- -z insert
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 TagNameand -l TagNameto include or exclude, respectively, tags from ScalaTest's tagging support, and -tto match an exact test name.
这会运行名称中带有“insert”的所有测试,然后只运行以 结尾的套件中的匹配案例TreeSpec,正如您的直觉。您还可以使用-n TagName和-l TagName分别包含或排除来自 ScalaTest 标记支持的标记,并-t匹配准确的测试名称。
Specs2 supports full Java regular expressionswith an -exargument:
Specs2支持带有-ex参数的完整 Java 正则表达式:
> testOnly -- -ex ".*someRexExp.*"
-includeand -excludesupport Spec2's tagging features.
-include并-exclude支持 Spec2 的标签功能。
See the inline links for full lists of arguments that the runners support. These appear to only work with the testOnlysbt command and not test.
有关运行程序支持的完整参数列表,请参阅内联链接。这些似乎只适用于testOnlysbt 命令,而不适用于test.

