Java 如何使用JMockit模拟void方法异常
我在尝试模拟void方法异常时遇到问题Java 如何使用JMockit模拟void方法异常,java,unit-testing,spring-test,jmockit,Java,Unit Testing,Spring Test,Jmockit,我在尝试模拟void方法异常时遇到问题 @Test public void throwInternalServerException() throws Exception { new NonStrictExpectations() {{ mockedClassInstance.voidMethod("abc", "def"); result = new ServiceException(); }}; mockMvc.perform
@Test
public void throwInternalServerException() throws Exception {
new NonStrictExpectations() {{
mockedClassInstance.voidMethod("abc", "def");
result = new ServiceException();
}};
mockMvc.perform(post("/someRestApi/"))
.andExpect(status().isInternalServerError());
在上面的代码中,如果我用anyString替换params“abc”和“def”,则会成功
我尝试了解决问题的方法,但不起作用
有解决办法吗
我使用了library:jmockit和spring test。在场景中使用关键字
anystring
,无论参数是什么(在本例中为'abc'和'def'),它都会抛出异常。在场景中使用关键字anystring
,无论参数是什么(在本例中为'abc'和'def'),它将抛出异常
@Test
public void throwInternalServerException() throws Exception {
new NonStrictExpectations() {{
mockedClassInstance.voidMethod("abc", "def");
result = new ServiceException();
}};
mockMvc.perform(post("/someRestApi/"))
.andExpect(status().isInternalServerError());