Junit 测试用例失败:
必须取消注册现有的静态模拟注册
测试类:
@RunWith(MockitoJUnitRunner.class)
public class DeleteReportServiceTest {
@InjectMocks
private ReturnCheckController returnCheckController;
@Mock
MockedStatic<DigitalGatewayRESTClient> mockDigiGateway;
@Before
public void setUp() throws Exception {
this.returnCheckController = new ReturnCheckController();
this.mockDigiGateway = Mockito.mockStatic(DigitalGatewayRESTClient.class);
}
@Test
public void testdeleteReport() throws Exception {
String input = "{\"clientId\": \"1\", \"applicationId\": \"9010\"}";
String response = "{\"success\":true,\"successText\":\"Manual adjustment record deleted\"}";
String expected = "{\"status\":200}";
JSONObject returnJson = new JSONObject(response);
mockDigiGateway.when((Verification) DigitalGatewayRESTClient.getDGRESTConnection(Mockito.any())).thenReturn(returnJson);
String actual = returnCheckController.deleteReport(input);
Assert.assertNotNull(actual);
Assert.assertEquals(expected, actual);
}
@After
public void after() {
mockDigiGateway.close();
}
}
Run Code Online (Sandbox Code Playgroud)
关闭静态模拟仍然出现错误。