使用 sbt 和 testng 时,如何获得测试中抛出的异常的完整堆栈跟踪? [英] How can I get complete stacktraces for exceptions thrown in tests when using sbt and testng?
问题描述
堆栈跟踪被截断 - 例如它们以 [info] ...
The stacktraces are truncated - e.g. they end with [info] ...
使用 last
或更改 traceLevel
没有帮助 - 它只是打印 sbt 包装器的完整堆栈跟踪.
Using last
or changing traceLevel
doesn't help - it simply prints the complete stacktrace of the sbt wrapper.
这是用 testng 测试(我也相信使用 scalatest 和 sl4j)
This is testing with testng (also I believe using scalatest and sl4j)
推荐答案
使用文档中的提示:
(引用)
您可以通过四种方式配置使用 sbt 运行时显示的输出:1) 关闭颜色,2) 显示短堆栈跟踪,3) 完整堆栈跟踪,以及 4) 显示所有内容的持续时间.为此,您必须将 -o 参数传递给 ScalaTest,并在 -o 之后放置以下任意组合:
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 - 显示持续时间
- S - 显示短堆栈跟踪
- F - 显示完整的堆栈跟踪
- W - 没有颜色
例如,-oDF"会显示完整的堆栈跟踪和持续时间(每次测试花费的时间).
For example, "-oDF" would show full stack traces and durations (the amount of time spent in each test).
要将参数从 sbt 传递给 ScalaTest,您可以全局添加测试选项,如下所示:
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)
您可以使用以下 sbt 命令在测试中启用完整的堆栈跟踪:
You can use the following sbt command to enable full stack traces in tests:
> set testOptions in YourProjectName += Tests.Argument("-oF")
<小时>
根据 Sasha 的评论,这也可以在每次测试运行时从命令行完成,如下所示.
Per Sasha's comment, this can also be done from the command line per test run as shown below.
$ sbt test -- -oF
这篇关于使用 sbt 和 testng 时,如何获得测试中抛出的异常的完整堆栈跟踪?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!