1

We have thousands of tests, and one is stuck (some infinite loop probably).

I'd like to know which tests is running but sbt only displays tests that are done. It also shows the tests titles, but as I said, we have too many tests to know which title the stuck test is part of.

Mario Galic
  • 47,285
  • 6
  • 56
  • 98
Juh_
  • 14,628
  • 8
  • 59
  • 92

1 Answers1

1

Try using runner arguments to configure a file reporter

-f output.txt

in combination with unformatted or "ugly" mode flag 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.

and then tail the output file during test execution

tail -f output.txt

which will show events in realtime as they are happening as opposed to at the end of testing.

Now given following example

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)
  }
}

then tail -f output.txt outputs

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)

where we can identify the stuck test on the last line.

Mario Galic
  • 47,285
  • 6
  • 56
  • 98
  • To run it from sbt command line, use something like `sbt "test-only -- -fU output.txt"` (see "specifying scalatest argument" section of http://www.scalatest.org/user_guide/using_scalatest_with_sbt). When there is lot's of tests, it's quite complicated to trace. But it does the trick. – Juh_ Oct 05 '18 at 07:53
  • 1
    I've put all the command I used here: https://gist.github.com/julien-diener/3ac5ba3e34dac6ff965b1cd3cba09d13 – Juh_ Oct 05 '18 at 08:16