allure-framework / allure-java

Allure integrations for Java test frameworks
Apache License 2.0
341 stars 218 forks source link

Inherited test methods don't support their annotations (fixes #1032) #1033

Open ingvard opened 2 months ago

ingvard commented 2 months ago

fixes #1032

Context

The getTestMethod method in the io.qameta.allure.junitplatform.AllureJunitPlatformUtils class doesn't function as expected for tests that are inherited. This is because it uses aClass.getDeclaredMethods(), which only operates on the current instance and does not include methods that are inherited. This can cause issues with annotations related to methods, such as descriptions and others.

Revision 1

In this revision, I used the aClass.getMethods() that returns all public methods on a checking class.

Revision 2

However, revision 1 covers one of the test cases when all test methods are public. It doesn't work when:

  1. Methods have package-based visibility that is usually for unit tests.
    public abstract static class ParentTest implements GrandparentTest {
        @Test
        @Description(TEST_DESCRIPTION)
        @Story(INHERITED_TEST_PARENT_STORY)
        @Link(TEST_LINK)
        void parentTest() {}
    }
  2. Methods are members of the interface (as default methods).
    public interface GrandparentTest {
        @Test
        @Description(TEST_DESCRIPTION)
        @Story(INHERITED_TEST_GRANDPARENT_STORY)
        @Link(TEST_LINK)
        default void grandparentTest() {}
    }
  3. Parent class has an upper-class annotation that must be applied to all inheritors.
    @Epic(INHERITED_TEST_EPIC)
    @Feature(INHERITED_TEST_FUTURE)
    public interface GrandparentTest { }

In short, I have to implement two methods placed into ReflectionUtils to recursively collect method and annotation information. These methods are designed as simplified logic of org.springframework.data.util.ReflectionUtils specifically for our needs.

Checklist

CLAassistant commented 2 months ago

CLA assistant check
All committers have signed the CLA.