akka 如何在Scalatest中拦截Future中的异常?

tnkciper  于 2022-11-06  发布在  Scala
关注(0)|答案(1)|浏览(118)

我正在尝试拦截测试中的异常(带有异常消息)。
我的测试代码:

class Test4 extends WordSpec with Matchers with ScalaFutures with ScalatestRouteTest {

"should fail if no valid" should {
  "should throw ex if name is not valid" in {
    whenReady(userService.createUser(wrongNameRequest)) {
      _ shouldBe UserCreateException("incorrect name")
    }
  }
}

但是看起来scalatest没有对我的“应该”做出正确的React。它表现得好像没有拦截存在一样。(我可以肯定:_ shouldBe用户创建异常(“不正确的名称”))
所以在测试结果中,我得到了这个:

- should should throw ex if a name is not valid***FAILED***
[info]     The future returned an exception of type: userapi.model.UserCreateException, with the message:  incorrect name.
cnwbcb6i

cnwbcb6i1#

解决了,我应该用全名-

_ shouldBe userapi.model.UserCreateException(" incorrect name")

相关问题