[英]Test succeeds in Idea IntelliJ but fails using Maven command
我有一个非常简单的单元测试,尽可能简单
@Test
public void testHandleInterruptedException() {
InterruptedException exception = Mockito.mock(InterruptedException.class);
Assertions.assertNotNull(YammerService.handleInterruptedException(exception, Boolean.TRUE));
Assertions.assertNotNull(YammerService.handleInterruptedException(exception, Boolean.FALSE));
}
奇怪的是,这个测试在从 maven build 命令运行时失败,而在 IntelliJ 中运行时通过。
方法 handleInterruptedException 也很简单 -
public static KendraConnectorException handleInterruptedException(
InterruptedException e, boolean isContinuable) {
return isContinuable ? new ContinuableInternalServerError(
"Current thread has been interrupted", e)
: new InternalServerError("Please try again later", e);
}
我不确定为什么它会因 maven 命令而失败。
尝试使用一个对象并将其发送到服务而不是模拟它
@Test
public void testHandleInterruptedException() {
// Arrange
InterruptedException exception = new InterruptedException("Test Interrupted exception msg");
// Act & Assert
Assertions.assertNotNull(YammerService.handleInterruptedException(exception, Boolean.TRUE));
Assertions.assertNotNull(YammerService.handleInterruptedException(exception, Boolean.FALSE));
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.