【问题标题】:unit test for catch block using kotlin mockito使用 kotlin mockito 对 catch 块进行单元测试
【发布时间】:2021-09-02 19:18:40
【问题描述】:
    try {
    return Response.ok(payHandler.getFeesForPay(body, config)).build()
    }



    catch (e: Exception) {
    return exceptionHelper.buildResponseFromException(e)
    }

如何使用 mockito 为 catch 块中的代码编写单元测试

【问题讨论】:

    标签: unit-testing kotlin junit mockito try-catch


    【解决方案1】:

    如果没有更详细的代码,我们只能建议您模拟payHandler 以抛出异常,如下所示:

    when(payHandler.getFeesForPay(any(), any()))
       .thenThrow(NullPointerException.class);
    

    【讨论】:

      猜你喜欢
      • 2020-06-08
      • 2018-05-13
      • 1970-01-01
      • 2017-11-22
      • 1970-01-01
      • 2013-12-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多