allure-java icon indicating copy to clipboard operation
allure-java copied to clipboard

Allure cannot detect proper junit5 lifecycle flow: missing BeforeAllCallback and AfterAllCallback

Open mszajowskiwr opened this issue 4 years ago • 0 comments

Describe the bug The allure reports do not contain attachments added in BeforeAllCallback/AfterAllCallback

To Reproduce Run the following code with junit 5:

import io.qameta.allure.Allure;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.AfterAllCallback;
import org.junit.jupiter.api.extension.AfterEachCallback;
import org.junit.jupiter.api.extension.AfterTestExecutionCallback;
import org.junit.jupiter.api.extension.BeforeAllCallback;
import org.junit.jupiter.api.extension.BeforeEachCallback;
import org.junit.jupiter.api.extension.BeforeTestExecutionCallback;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.extension.ExtensionContext;

@ExtendWith({AllureIssueExtension.class})
public class AllureIssueTest {

    @BeforeAll
    static void beforeAll() {
        Allure.addAttachment("static beforeAll in test class", "something");
    }

    @BeforeEach
    void beforeEach() {
        Allure.addAttachment("beforeEach in test class", "something");
    }

    @Test
    void someTest() {
        Allure.addAttachment("someTest in test class", "something");
    }

    @AfterEach
    void afterEach() {
        Allure.addAttachment("afterEach in test class", "something");
    }

    @AfterAll
    static void afterAll() {
        Allure.addAttachment("static afterAll in test class", "something");
    }
}

class AllureIssueExtension implements BeforeAllCallback, BeforeEachCallback, BeforeTestExecutionCallback,
    AfterTestExecutionCallback, AfterEachCallback, AfterAllCallback {

    @Override
    public void beforeAll(final ExtensionContext context) {
        Allure.addAttachment("BeforeAllCallback in AllureIssueExtension", "something");
    }

    @Override
    public void beforeEach(final ExtensionContext context) {
        Allure.addAttachment("BeforeEachCallback in AllureIssueExtension", "something");
    }

    @Override
    public void beforeTestExecution(final ExtensionContext context) {
        Allure.addAttachment("BeforeTestExecutionCallback in AllureIssueExtension", "something");
    }

    @Override
    public void afterTestExecution(final ExtensionContext context) {
        Allure.addAttachment("AfterTestExecutionCallback in AllureIssueExtension", "something");
    }

    @Override
    public void afterEach(final ExtensionContext context) {
        Allure.addAttachment("AfterEachCallback in AllureIssueExtension", "something");
    }

    @Override
    public void afterAll(final ExtensionContext context) {
        Allure.addAttachment("AfterAllCallback in AllureIssueExtension", "something");
    }
}

Expected behavior There should be 11 attachments in the allure report.

Actual behavior The attachments made in BeforeAllCallback and AfterAllCallback are missing:

Screenshots image

Additinal context It seems that the allure lifecycle is not started when the extensions are working. Here are the logs produced during BeforeAllCallback and AfterAllCallback work:

[ForkJoinPool-1-worker-3] ERROR AllureLifecycle - Could not add attachment: no test is running

mszajowskiwr avatar Nov 04 '21 12:11 mszajowskiwr