问题描述
我在杀死某些突变时遇到了一些麻烦,我不明白为什么。
这是我正在测试的课程
@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 语句中的 2 行仍然存在。我遗漏了什么/没有测试什么?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)