首页 > 解决方案 > 从嵌套套件运行特定测试

问题描述

考虑以下Suites包含几个嵌套Suites

package example

import org.scalatest.{DoNotDiscover, Suites}
import org.scalatest.funsuite.AnyFunSuite

@DoNotDiscover
class NestedSuite1 extends AnyFunSuite  {
  test("A") {}
  test("B") {}
}
@DoNotDiscover
class NestedSuite2 extends AnyFunSuite  {
  test("A") {}
  test("B") {}
}
class ContainingSuite extends Suites(
  new NestedSuite1,
  new NestedSuite2
)

如何具体执行,比如B测试NestedSuite2via ContainingSuite?注意我不是说

Test/runMain org.scalatest.tools.Runner -o -s example.NestedSuite2 -t B

因为那绕过了ContainingSuite。相反,我追求的是

Test/runMain org.scalatest.tools.Runner -o -s example.ContainingSuite -i example.NestedSuite2 -t B

然而,它同时执行ABNestedSuite2

sbt:scalatest-seed-3.2.0> Test/runMain org.scalatest.tools.Runner -o -s example.ContainingSuite -i example.NestedSuite2 -t B
[info] running org.scalatest.tools.Runner -o -s example.ContainingSuite -i example.NestedSuite2 -t B
Run starting. Expected test count is: 2
NestedSuite1:
NestedSuite2:
- A
- B
Run completed in 72 milliseconds.
Total number of tests run: 2
Suites: completed 3, aborted 0
Tests: succeeded 2, failed 0, canceled 0, ignored 0, pending 0
All tests passed.

与类似的预期输出相反

NestedSuite1:
NestedSuite2:
- B
Run completed ...

选择套件和测试记录-s,-i-trunner 参数如下

-s将用于指定 ScalaTest 可以直接实例化的类,包含具有公共、无参数构造函数的套件,-i并将用于选择所需的嵌套套件...该-t 参数允许通过其选择测试(完整) 测试名称...如果 a-t跟在-s-i之后,则它仅适用于标识的套件。

注意我使用的是Test/runMain org.scalatest.tools.Runnerinsted of,testOnly因为目前它不适用于注释DoNotDiscover

标签: scalasbtscalatest

解决方案


推荐阅读