我有以下代码行,Jacoco 将其指示为未“执行”。
但是当我调试测试用例时,它确实执行了这些行。下面是我写的测试用例。
@PrepareForTest({MessagingAdapterFactory.class, MessagingConfigReaderFactory.class,UpdaterServiceExecutor.class,Files.class})
@Test
public void should_shutDown_the_scheduledExecutor_and_close_the_messagingAdapter() throws Exception {
PowerMockito.mockStatic(Files.class);
PowerMockito.when(Files.exists(any())).thenReturn(true);
PowerMockito.mockStatic(MessagingAdapterFactory.class);
PowerMockito.when(MessagingAdapterFactory.getMessagingAdapter("edgeNode")).thenReturn(messagingAdapterMock);
PowerMockito.mockStatic(MessagingConfigReaderFactory.class);
PowerMockito.when(MessagingConfigReaderFactory.getConfigurationReader()).thenReturn(readerMock);
ScheduledExecutorService scheduledExecutorServiceMock = Mockito.mock(ScheduledExecutorService.class);
PowerMockito.mockStatic(Executors.class);
PowerMockito.when(Executors.newSingleThreadScheduledExecutor()).thenReturn(scheduledExecutorServiceMock);
when(readerMock.getConfigParams()).thenReturn("somePath,somePath,somePath");
when(decompressUtilMock.decompressZip(Matchers.anyString(),Matchers.anyString())).thenReturn(true);
when(checkSumUtilMock.check(anyString(), anyString())).thenReturn(true);
when(commandExecutorMock.executeCommand("somePath verify /pa somePathKubeUpdates/KubePlatformSetup.exe")).thenReturn(false);
updaterServiceExecutor.execute();
Thread.sleep(10000);
updaterServiceExecutor.close();
verify(scheduledExecutorServiceMock,timeout(10000).times(1)).shutdownNow();
verify(messagingAdapterMock,timeout(10000).times(1)).close();
}
@PrepareForTest({MessagingAdapterFactory.class, MessagingConfigReaderFactory.class,UpdaterServiceExecutor.class,Files.class})
@Test
public void should_not_throw_ServiceSDKException_when_occurred_while_closing_the_messagingAdapter() throws Exception {
PowerMockito.mockStatic(Files.class);
PowerMockito.when(Files.exists(any())).thenReturn(true);
PowerMockito.mockStatic(MessagingAdapterFactory.class);
PowerMockito.when(MessagingAdapterFactory.getMessagingAdapter("edgeNode")).thenReturn(messagingAdapterMock);
PowerMockito.mockStatic(MessagingConfigReaderFactory.class);
PowerMockito.when(MessagingConfigReaderFactory.getConfigurationReader()).thenReturn(readerMock);
ScheduledExecutorService scheduledExecutorServiceMock = Mockito.mock(ScheduledExecutorService.class);
PowerMockito.mockStatic(Executors.class);
PowerMockito.when(Executors.newSingleThreadScheduledExecutor()).thenReturn(scheduledExecutorServiceMock);
when(readerMock.getConfigParams()).thenReturn("somePath,somePath,somePath");
when(decompressUtilMock.decompressZip(Matchers.anyString(),Matchers.anyString())).thenReturn(true);
when(checkSumUtilMock.check(anyString(), anyString())).thenReturn(true);
when(commandExecutorMock.executeCommand("somePath verify /pa somePathKubeUpdates/KubePlatformSetup.exe")).thenReturn(false);
doThrow(new ServiceSDKException()).when(messagingAdapterMock).close();
updaterServiceExecutor.execute();
Thread.sleep(10000);
updaterServiceExecutor.close();
verify(scheduledExecutorServiceMock,timeout(10000).times(1)).shutdownNow();
verify(messagingAdapterMock,timeout(10000).times(1)).close();
}
这里有什么问题?为什么 Jacoco 显示为行尚未执行?请指教。