scala 如何从 maven 在 Scalatest 中运行单个测试

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24852484/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-22 06:25:25  来源:igfitidea点击:

How to run a single test in scalatest from maven

scalamavenscalatest

提问by javadba

I have not found any documentation on how to do this. For JUnit the equivalent would be:

我还没有找到任何有关如何执行此操作的文档。对于 JUnit,等效项是:

mvn -Dtest=org.apache.spark.streaming.InputStreamSuite test

回答by user1132007

tl;drmvn test -Dsuites="some.package.SpecsClass"

tl;博士mvn test -Dsuites="some.package.SpecsClass"



I found an answer from here and it works:(https://groups.google.com/forum/#!topic/scalatest-users/Rr0gy61dg-0)

我从这里找到了一个答案并且它有效:( https://groups.google.com/forum/#!topic/scalatest-users/Rr0gy61dg-0)

run test 'a pending test' in HelloSuite, and all tests in HelloWordSpec:

在 中运行 test 'a pending test' HelloSuite,并在 中运行所有测试HelloWordSpec

 mvn test -Dsuites='org.example.
HelloSuite @a pending test, org.example.HelloWordSpec' 
  • run all tests in HelloSuitecontaining 'hello':

    mvn test-Dsuites='org.example.HelloSuitehello'

  • 运行HelloSuite包含的所有测试'hello'

    mvn test-Dsuites='org.example.HelloSuitehello'

for more details: http://scalatest.org/user_guide/using_the_scalatest_maven_plugin

更多详情:http: //scalatest.org/user_guide/using_the_scalatest_maven_plugin

回答by javadba

Found the answer: it is

找到答案:是

-DwildcardSuites

So here is the example command line:

所以这是示例命令行:

mvn -pl streaming -DwildcardSuites=org.apache.spark.streaming.InputStreamSuite test

UpdateNewer versions of scalatestuse

更新较新的scalatest使用版本

 -Dsuites

So the syntax would be:

所以语法是:

mvn -pl streaming -Dsuites=org.apache.spark.streaming.InputStreamSuite test

回答by Steve Loughran

Note that if you have some Java tests in the same module, as much of spark does, you need to turn them off -which you can do by telling surefire to run a test that isn't there

请注意,如果您在同一模块中有一些 Java 测试,就像 spark 所做的那样,您需要将它们关闭 - 您可以通过告诉 surefire 运行不存在的测试来实现

Here is the test that I've just been running

这是我刚刚运行的测试

mvn test -Dtest=moo -DwildcardSuites=org.apache.spark.deploy.yarn.ClientSuite

That skips the java test and only runs the scala one.

这会跳过 java 测试,只运行 Scala 测试。

One thing which scalatest doesn't seem to do is let you run a single test within a suite, the way maven surefire does. That's not ideal if you have one failing test in a big suite.

scalatest 似乎没有做的一件事是让您在套件中运行单个测试,就像 maven surefire 那样。如果您在大型套件中进行了一项失败的测试,那这并不理想。

[Correction 2016-08-22: looks like you can ask for a specific suite by name; look at the other answers below. Happy to be wrong].

[更正 2016-08-22:看起来您可以按名称要求特定套房;看看下面的其他答案。乐于犯错]。