Skip to content

[junit5] DisplayNameGenerator is ignored for class name #500

@scormaq

Description

@scormaq

I'm submitting a ...

  • bug report

What is the current behavior?

With Junit5 it is possible to use Display name generators to improve test names automatically.

Allure-junit5 is supposed to print suite/test names from displayName value if it is available. While it works correctly for methods (testIdentifier.getDisplayName() is used), it does not work for classes (@DisplayName annotation value is looked, so values from name generator are ignored).

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem

  1. Using junit5 + allure, set up DisplayNameGenerator like next:
MyDisplayNameGenerator.java
import java.lang.reflect.Method;
import org.junit.jupiter.api.DisplayNameGenerator;

public class MyDisplayNameGenerator implements DisplayNameGenerator {

    @Override
    public String generateDisplayNameForClass(Class<?> testClass) {
        return "le test suite";
    }

    @Override
    public String generateDisplayNameForNestedClass(Class<?> nestedClass) {
        return "nested class";
    }

    @Override
    public String generateDisplayNameForMethod(Class<?> testClass, Method testMethod) {
        return "test method";
    }
}
  1. Apply it to test:
MyTest.java
import org.junit.jupiter.api.DisplayNameGeneration;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;

@DisplayNameGeneration(MyDisplayNameGenerator.class)
public class MyTest {
    @Test
    void testSomething() {}

    @Nested
    class NestedClass {
        @Test
        void testAnotherThing() {}
    }
}
  1. Execute test & generate allure report
    image
    execution in IDEA to prove that generator works as expected

image
generated Allure report

What is the expected behavior?

Allure should get displayed class/nested class name from provided DisplayNameGenerator

What is the motivation / use case for changing the behavior?

  • Make test maintenance easier (I can supply single DisplayNameGenerator which will turn class or method names into human-readable sentences for example, and do not use @DisplayName annotations; or even apply whatever complex custom mechanizm);
  • Improve allure-junit5 integration (I would like to leverage junit5 capabilities to improve my allure experience)

Please tell us about your environment:

Allure version 2.13.7
Test framework junit5@5.7.0
Allure integration allure-junit5@2.13.7
Generate report using allure-gradle@2.8.1

Other information

N.B. Maybe it is worthy to provide, along with fix, some mechanism that will provide human-readable class/method names by default (controlled by some allure property)? IMHO it could be useful to prettify report for all the existing tests by 1 property enabled if no displayName provided in tests (in any way - annotations/ generators etc).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions