我使用specs2作为我的测试框架。我想模拟一个用例,其中actionA返回一个失败的future。就像这样:
val actionA = mock[ActionA]
val actionB = new ActionB(actionA)
actionA.doSomthing(x) returns Future.failed(new Exception("bla"))
try {
Await.result(actionB.doSomthing(request), 1 seconds)
}catch {
case e: Exception => println("exception caught: " + e);
}
字符串
问题是,如果我没有捕捉到这个异常,我的测试会带着这个异常退出,难道specs2没有更好的方法来吞下异常吗?有没有更好的方法来测试这种情况?
谢谢你,谢谢
1条答案
按热度按时间zpjtge221#
字符串
通过https://etorreborre.github.io/specs2/guide/SPECS2-5.2.0/org.specs2.guide.Matchers.html#for-exception-values->异常