如何在mockito中执行catch块以进行代码覆盖?

问题描述

我打算执行 catch 块以实现 90% 的声纳覆盖率。这是代码


@H_502_4@public Map<Integer,Triplet<Integer,Integer,Integer>> getResult(int num1,List<Integer> numbers) {
    List<Triplet<Integer,Integer>> result;
    try {
        result = innerMethod(Util.getRes(num1),num1,numbers);
        return result;
    }

}

我尝试了以下方法

@H_502_4@public void Exceptest(){
    //Tried method 1
    when(mockObj.getResult(anyInt(),anyList())).thenThrow(mock(Exception.class));
    //Tried method 2
    doThrow(new RuntimeException()).when(mockObj).getResult(anyInt(),anyList());
    //Tried method 3
    doThrow(new RuntimeException()).when(mockObj.getResult(anyInt(),anyList()));

}

它抛出 invocationTaget 异常而不是去那个 catch 块。在那个innerMethod中,一些数据库连接带有try-catch块。

如何执行那个catch块?有人可以帮我吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)