How can I get complete stacktraces for exceptions thrown in tests when using sbt and testng?

佐手、 提交于 2019-12-20 08:35:04

问题


The stacktraces are truncated - e.g. they end with [info] ...

Using last or changing traceLevel doesn't help - it simply prints the complete stacktrace of the sbt wrapper.

This is testing with testng (also I believe using scalatest and sl4j)


回答1:


Using hints found in the documentation here:

(quoted)

You can configure the output shown when running with sbt in four ways: 1) turn off color, 2) show short stack traces, 3) full stack traces, and 4) show durations for everything. To do so you must pass a -o argument to ScalaTest, and after the -o, place any combination of:

  • D - show durations
  • S - show short stack traces
  • F - show full stack traces
  • W - without color

For example, "-oDF" would show full stack traces and durations (the amount of time spent in each test).

To pass arguments from sbt to ScalaTest you can either add test options globally, like this:

testOptions in Test += Tests.Argument("-oD")

(See the website for the rest of the quote)

You can use the following sbt command to enable full stack traces in tests:

> set testOptions in YourProjectName += Tests.Argument("-oF")

Per Sasha's comment, this can also be done from the command line per test run as shown below.

$ sbt test -- -oF



回答2:


As an alternative to getting SBT to print the full stack trace, could you put a try-catch block around your test runner? For example, from the REPL:

scala> try { throw new Exception } catch { case e => e }
res1: java.lang.Throwable = java.lang.Exception

scala> res1.printStackTrace
java.lang.Exception
    at $line2.$read$$iw$$iw$.liftedTree1$1(<console>:8)
    at $line2.$read$$iw$$iw$.<init>(<console>:8)
    at $line2.$read$$iw$$iw$.<clinit>(<console>)
    ...


来源:https://stackoverflow.com/questions/7237824/how-can-i-get-complete-stacktraces-for-exceptions-thrown-in-tests-when-using-sbt

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!