gpt4 book ai didi

java - 需要在 public void testWhenRespWriterIsNull() 内进行断言 throws IOException

转载 作者:行者123 更新时间:2023-12-01 18:18:38 24 4
gpt4 key购买 nike

我想在下面的 IOException 中编写断言。

public void testWhenRespWriterIsNull() throws IOException {
when(response.getWriter()).thenThrow(IOException.class);
when(request.getParameter("version")).thenReturn(null);
logoutServlet.doPost(request, response);
exceptionRule.equals(IOException.class);
}

更新:我在 SonarQube 中收到以下错误

Add at least one assertion to this test case.

由于我是 JUNIT 新手,所以我不知道需要在上面的 testWhenRespWriterIsNull() 中编写哪个断言。

最佳答案

如果您已有exceptionRule.equals(IOException.class);,则无需任何其他 Assert 语句。此语句验证是否抛出了 IOException

您可能想测试抛出的异常中的错误消息,通过

exceptionRule.expectMessage("对于输入字符串");

有关在 Junits 中断言异常的更多示例,请查看 Junit Assert Exceptions

关于java - 需要在 public void testWhenRespWriterIsNull() 内进行断言 throws IOException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60319550/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com