Stacktraces on custom exceptions in Specs2 pins

In our tests, we make extensive use of stubs, some of which throw and throw exceptions. I found that just by throwing an exception calls the stack that pops up when our tests run. This means that there is a large amount of unnecessary and confusing noise, since we do not care about these โ€œexpectedโ€ exceptions. I browsed the Internet, but I canโ€™t find anything about silencing these stacks (only that in reality the exceptions that were thrown elsewhere in the code or within the framework), I would like to show the trace. This is a common problem, and has anyone found a way to overcome it?

Sorry for example:

val t = new Throwable("Expected exception") val service = new AuthenticationService()(ExceptionThrowingClient(t)) 

Test run results using stacktrace, which looks something like this:

 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] 

Which will return to the instantiation point in the specification.

+6
source share

Source: https://habr.com/ru/post/986986/


All Articles