Junit5. Как Аттачить логи SL4J к Allure?
Следующая проблема - пишу API тесты, стек - java+rest-assured+junit5+lombok. Используется @sl4j логгер. Хотелось бы сделать так, чтобы весь лог выполднения теста ложился в качестве аттача к соответствующей сущности в Allure. Нашёл решение для TestNg http://automation-remarks.com/2017/rest-assured-allure-log/index.html Для 4го Junit решение, как понимаю, будет в каком то таком виде:
public class TestListener extends RunListener {
@Override
public void testStarted(Description description) throws Exception {
//Здесь соответствующие действия для логов
}
@Override
public void testFinished(Description description) throws Exception {
}}
Как подобное сделать для Junit5? Указанный ниже код не работает:
@Slf4j
public class Listener implements TestExecutionListener, TestWatcher {
private ByteArrayOutputStream request = new ByteArrayOutputStream();
private ByteArrayOutputStream response = new ByteArrayOutputStream();
private PrintStream requestVar = new PrintStream(request, true);
private PrintStream responseVar = new PrintStream(response, true);
public void executionStarted(TestIdentifier testIdentifier) {
RestAssured.filters(new ResponseLoggingFilter(LogDetail.ALL, responseVar),
new RequestLoggingFilter(LogDetail.ALL, requestVar));
}
public void executionFinished(TestIdentifier testIdentifier, TestExecutionResult testExecutionResult) {
logRequest(request);
logResponse(response);
}
@Attachment(value = "request", type = "text/html")
public byte[] logRequest(ByteArrayOutputStream stream) {
return attach(stream);
}
@Attachment(value = "response", type = "text/html")
public byte[] logResponse(ByteArrayOutputStream stream) {
return attach(stream);
}
public byte[] attach(ByteArrayOutputStream log) {
byte[] array = log.toByteArray();
log.reset();
return array;
}
}