我有一个使用
@ExtendWith(OutputCaptureExtension.class)
的测试用例,测试用例如下。
@Test
void testOneSimpleMethodWhichHaveDebugLogs(CapturedOutput output) {
....//// When then and everything is here.
Object param = Mockito.mock(Object.class);
Object.setExampleMap(map);
Mockito.when(param.getMap()).thenReturn(map);
ImplementationOfSomeAbstractClass obj = new ImplementationOfSomeAbstractClass();
Status result = obj.validation(param);
assertEquals(StatusEnum.NO_CHANGE, result);
assertTrue(output.getAll().contains("Some Text"));
}
具有logger方法的类如下。
@Slf4j
@RequiredArgsConstructor
public abstract class SomeAbstractClass {
protected Status validation(Object param) {
Status result = Status.UNKNOWN;
try {
param1 = someOtherPrivateMethod();
result = anotherProtectedMethod(param, param1);
} catch (Exception e) {
log.error("Invalid.", e);
}
return result;
}
protected Result anotherProtectedMethod(Object param, Object param1) {
try {
if (somCondition) {
log.error("SomeText");
}
if (somCondition) {
log.warn("SomeText");
}
if (somCondition) {
log.info("SomeText");
}
if (somCondition) {
log.debug("SomeText");
} else {
log.info("SomeText");
log.info("SomeText");
}
} catch (Exception exp) {
log.error("SomeText");
}
log.error("SomeText");
return null;
}
}
所有其他日志级别都会打印在控制台上,但不知何故调试日志不会打印在控制台上,只有这个测试用例失败。
请帮忙。
你找到解决办法了吗?
谢谢你