sbt testOnly 运行多个测试

sbt testOnly runs multiple tests

当我运行:

sbt testOnly com.blablabla.A

我得到以下输出:

[error] Failed: Total 19, Failed 6, Errors 0, Passed 13, Ignored 6
[error] Failed tests:
[error]         com.blablabla.A
[error]         com.blablabla.B
[error]         com.blablabla.C
[error] (test:testOnly) sbt.TestsFailedException: Tests unsuccessful
[error] Total time: 13 s, completed Jul 1, 2020 12:35:08 PM

为什么?

我只想考A.

尝试

sbt "testOnly com.blablabla.A"

原因

sbt testOnly com.blablabla.A

不起作用是因为这里 sbt 在 batch mode 中运行,这意味着它将每个 space-separated 值视为一个单独的命令并尝试执行他们按顺序。例如,它将 testOnly 视为一个命令,然后将 com.blablabla.A 视为下一个命令

sbt    testOnly      com.blablabla.A
          |                  |
      1st command      2nd command

解决方案是将本身带有参数的命令括在引号中

sbt    clean        compile     "testOnly       TestA TestB"
         |            |             |                |
    1st command   2nd command    3rd command    args to 3rd command