如何知道当前是哪个测试 运行

How to know which test is currently running

我们有数千个测试,其中一个被卡住了(可能是无限循环)。

我想知道哪些测试是 运行 但 sbt 只显示已完成的测试。它还显示了测试标题,但正如我所说,我们有太多测试无法知道卡住测试属于哪个标题。

尝试使用runner arguments配置文件报告器

-f output.txt

结合未格式化或"ugly"模式标志U which

Rather than attempting to make the output look as pretty and human-readable as possible, unformatted mode will just print out verbose information about each event as it arrives, helping you track down the problem you are trying to debug.

然后在测试执行期间拖尾输出文件

tail -f output.txt

这将实时显示正在发生的事件,而不是在测试结束时显示。

现在给出下面的例子

Test / testOptions += Tests.Argument("-fU", "output.txt")

class HelloSpec extends FlatSpec with Matchers {
  "The Hello object" should "satisfy case 1" in {
    assert(true)
  }

  it should "satisfy case 2" in {
    assert(true)
  }

  it should "satisfy case 3 (stuck here)" in {
    while(true) { /* do something forever */ }
    assert(true)
  }

  it should "satisfy case 4" in {
    assert(true)
  }
}

然后tail -f output.txt输出

Run starting. Expected test count is: 0
Suite Starting - HelloSpec
Scope Opened - HelloSpec: The Hello object
Test Starting - HelloSpec: The Hello object should satisfy case 1
Test Succeeded - HelloSpec: The Hello object should satisfy case 1
Test Starting - HelloSpec: The Hello object should satisfy case 2
Test Succeeded - HelloSpec: The Hello object should satisfy case 2
Test Starting - HelloSpec: The Hello object should satisfy case 3 (stuck here)

我们可以在最后一行识别卡住的测试。