[英]How can I mock a void method exception using JMockit
I have a problem when trying to mock void method exception. 我在尝试模拟void方法异常时遇到问题。
@Test
public void throwInternalServerException() throws Exception {
new NonStrictExpectations() {{
mockedClassInstance.voidMethod("abc", "def");
result = new ServiceException();
}};
mockMvc.perform(post("/someRestApi/"))
.andExpect(status().isInternalServerError());
In the codes above, its success if i replace params "abc" and "def" with anyString 在上面的代码中,如果我用anyString替换params “abc”和“def” ,它的成功
I tried the solution of this question but it does not work. 我尝试了这个问题的解决方案,但它不起作用。
Any solution? 有解决方案吗
I used library : jmockit and spring-test. 我使用了库:jmockit和spring-test。
在场景中使用关键字anystring
,当任何参数(在这种情况下,'abc'和'def')时,它将抛出异常。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.