我在杀死一些突变方面有点困难,我不明白为什么。
这是我正在测试的类
@Configuration
@EnableScheduling
public class TasksDeclaration {
private static final Logger LOGGER = LoggerFactory.getLogger(TasksDeclaration.class);
private final ErrorLogFactory errorLogFactory;
private final AccountConnectorClient accountConnectorClient;
private final PublisherClient publisherClient;
@Scheduled(cron = "${task.health-check.cron}")
public void verifyServicesAreRunning() {
DomainServiceStatus domainServiceStatus = DomainServiceStatus.INSTANCE;
try {
LOGGER.info("Verifying health status of - starting");
domainServiceStatus.setAccountConnectorUp(isAccountConnectorRunning());
domainServiceStatus.setPublisherUp(isPublisherRunning());
LOGGER.info("Verifying health status - done - services are running");
} catch (RetryableException ex) {
domainServiceStatus.setAccountConnectorUp(false);
domainServiceStatus.setPublisherUp(false);
}
}
private boolean isAccountConnectorRunning() {
ResponseEntity<HealthStatus> response = accountConnectorClient.HeathCheck();
return (response.getBody().getStatus().equals(SERVICE_UP));
}
private boolean isPublisherRunning() {
ResponseEntity<HealthStatus> response = publisherClient.HeathCheck();
return (response.getBody().getStatus().equals(SERVICE_UP));
}
}
这是我的测试方法
@Test
void verifyServicesAreRunning_error() throws FeignException {
when(accountConnectorClient.HeathCheck()).thenThrow(new RetryableException(500, "message", Request.HttpMethod.GET, new Date(), DataFixture.getRequest()));
tasksDeclaration.verifyServicesAreRunning();
verify(accountConnectorClient).HeathCheck();
assertFalse(DomainServiceStatus.INSTANCE.isAccountConnectorUp());
assertFalse(DomainServiceStatus.INSTANCE.isPublisherUp());
}
pit测试覆盖率报告告诉我catch语句中的两行代码仍然存在,尽管调用被删除。我遗漏了什么/没有测试什么?
暂无答案!
目前还没有任何答案,快来回答吧!