0

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


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

}

我尝试了以下方法,

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()));

}

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

如何执行那个 catch 块?谁可以帮我这个事?

4

0 回答 0