allure-framework / allure-java

Allure integrations for Java test frameworks
Apache License 2.0
355 stars 224 forks source link

🐞: [Junit 5] - Label parentSuite not applied for disabled tests #1103

Closed EvgeniyBulbenkov closed 2 months ago

EvgeniyBulbenkov commented 2 months ago

What happened?

When test marked as disabled, label parentSuite not applied for the test result with the error message ERROR io.qameta.allure.AllureLifecycle - Could not update test case: no test case running The potential reason - the method startTestContainer (of io.qameta.allure.junitplatform.AllureJunitPlatform class) not called, no test container created for processing label data)

Link to the repo with demo and detailed description https://github.com/EvgeniyBulbenkov/AllureDisabledTestIssue

What Allure Integration are you using?

allure-junit5

What version of Allure Integration you are using?

2.28.0

What version of Allure Report you are using?

2.28.0

Code of Conduct

baev commented 2 months ago

You can't use Allure Runtime API for JUnit 5 Disabled tests. Instead, I would suggest you to create a custom annotation:

package extensions;

import io.qameta.allure.LabelAnnotation;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Documented
@Inherited
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD, ElementType.TYPE})
@LabelAnnotation(
        name = "parentSuite"
)
public @interface ParentSuite {

    String value();

}

And then use it for tests (will work on both classes and methods):

package org.example.junit5;

import extensions.ParentSuite;
import io.qameta.allure.Allure;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

@DisplayName("BE: Service 007")
@ParentSuite("BE")
public class SuiteThreeTest {

    @Test
    @DisplayName("First database test")
    @Disabled
    public void firstIntegrationTest() {
    }

    @Test
    @DisplayName("Second database test")
    public void secondIntegrationTest() {
    }

    @Test
    @DisplayName("Third database test")
    public void thirdIntegrationTest() {
    }

    @Test
    @DisplayName("Fourth database test")
    public void fourthIntegrationTest() {
    }

    @Test
    @DisplayName("Fifth database test")
    public void fifthIntegrationTest() {
    }
}
Screenshot 2024-07-26 at 17 42 56
baev commented 2 months ago

You can also use custom annotations to add multiple labels/links at once:

package extensions;

import io.qameta.allure.Epic;
import io.qameta.allure.TmsLink;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Documented
@Inherited
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD, ElementType.TYPE})
@ParentSuite("BE")
@Epic("BE")
@TmsLink("BE-123")
public @interface Be {
}
package org.example.junit5;

import extensions.Be;
import io.qameta.allure.Allure;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

@DisplayName("BE: Service 007")
@Be
public class SuiteThreeTest {

    @Test
    @DisplayName("First database test")
    @Disabled
    public void firstIntegrationTest() {
    }

    @Test
    @DisplayName("Second database test")
    public void secondIntegrationTest() {
    }

}