使用 Scala 从 SBT 获取堆栈跟踪
上下文:在 SBT 管理的项目中编写 Scala 单元测试。
当我执行 sbt test 来运行我的单元测试时,断言在代码中的某处失败,我得到类似以下内容(仅此而已):
Test com.reach.ml.test.TestLSHEasy.T0 failed: assertion failed
这告诉我哪个单元测试导致断言失败,但不是哪个断言。如果我直接运行相同的测试(不使用 sbt),我会得到整个堆栈跟踪,这对于调试非常有用。所以我的问题是:当测试崩溃时,如何让 SBT 打印出堆栈跟踪?
Context: Writing Scala unit-tests in a project managed by SBT.
When I execute sbt test
to run my unit-tests an assert fails somewhere in my code, I get something like the following (and nothing more):
Test com.reach.ml.test.TestLSHEasy.T0 failed: assertion failed
This tells me which unit-test caused the assert fail, but not which assert it was. If I run the same test directly (not using sbt), I get a whole stack trace, which is very useful for debugging. So my question: How do I get SBT to print out the stack trace when a test crashes?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
关于xsbt,可能与
util.log.StackTrace
对象,可以修剪其输出。issue 118 说明了保留堆栈跟踪的意愿应该受到更好的控制:
也许您可以包装单元测试,拦截任何异常,并显式打印其完整堆栈跟踪? (如
Basic.scala
或Boot.scala
)。Regarding xsbt, it might be related to the
util.log.StackTrace
object which can trim its output.The issue 118 illustrated the will of keeping stack traces should be under better control:
Maybe you can wrap your unit test, intercepting any exception, and printing explicitely their full stack trace? (as in
Basic.scala
orBoot.scala
).