【发布时间】:2017-05-23 04:57:21
【问题描述】:
我在尝试模拟 void 方法异常时遇到问题。
@Test
public void throwInternalServerException() throws Exception {
new NonStrictExpectations() {{
mockedClassInstance.voidMethod("abc", "def");
result = new ServiceException();
}};
mockMvc.perform(post("/someRestApi/"))
.andExpect(status().isInternalServerError());
在上面的代码中,如果我用 anyString
替换参数 "abc" 和 "def" 则成功我尝试了this question的解决方案,但它不起作用。
有什么办法吗?
我使用了库:jmockit 和 spring-test。
【问题讨论】:
标签: java unit-testing spring-test jmockit