Mockito 可以扔将军Exception吗?
当我这样做时,测试失败并显示“org.mockito.exceptions.base.MockitoException: Checked Exception is invalid for this method”
这是我的 @Test
public void testServiceSomeError() throws ClientProtocolException, IOException {
//Arrange
HealthService service = Mockito.mock(HealthService.class);
when(service.executeX(HOST)).thenCallRealMethod();
when(service.getHTTPResponse("http://" + HOST + "/health")).thenThrow(Exception.class);
//Act
String actual = service.executeX(HOST);
//Assert
assertEquals(ERROR, actual);
}
慕田峪4524236
RISEBY
慕哥9229398
相关分类