Stacktraces用于Specs2输出中的用户实例化异常

use*_*262 6 error-handling scala playframework specs2 playframework-2.3

在我们的测试中,我们广泛使用存根,其中一些创建并抛出异常.我发现只是实例化一个异常,导致堆栈跟踪在我们的测试运行时出现.这意味着存在大量不必要和混乱的噪音,因为我们不关心这些"预期的"例外情况.我已经浏览了互联网,但找不到任何关于沉默这些堆栈跟踪的内容(记住,实际异常,在代码中的其他地方抛出,或者通过框架,我仍然希望显示跟踪).这是一个常见问题,有没有人找到解决办法?

对不起,举个例子:

val t = new Throwable("Expected exception")
val service = new AuthenticationService()(ExceptionThrowingClient(t))
Run Code Online (Sandbox Code Playgroud)

使用类似于下面的堆栈跟踪进行测试运行的结果:

java.lang.Throwable: Expected exception
at services.auth.AuthenticationServiceSpec$$anonfun$4.apply(ServiceSpec.scala:104) ~[test-classes/:na]
at services.auth.AuthenticationServiceSpec$$anonfun$4.apply(ServiceSpec.scala:103) ~[test-classes/:na]
at org.specs2.mutable.SideEffectingCreationPaths$$anonfun$executeBlock$1.apply$mcV$sp(FragmentsBuilder.scala:292) ~[specs2-core_2.10-2.3.12.jar:2.3.12]
at org.specs2.mutable.SideEffectingCreationPaths$class.replay(FragmentsBuilder.scala:264) ~[specs2-core_2.10-2.3.12.jar:2.3.12]
at org.specs2.mutable.Specification.replay(Specification.scala:12) ~[specs2-core_2.10-2.3.12.jar:2.3.12]
Run Code Online (Sandbox Code Playgroud)

其中追溯到规范中的实例化点.