Skip to content

[SUREFIRE-2194] JUnit 5: Implementing tests in test class and nested class results in incorrect reporting #2682

@jira-importer

Description

@jira-importer

Jochen Kraushaar opened SUREFIRE-2194 and commented

Example Test Class

import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertTrue;

class ExampleTest {

    @Test
    void outerTest() {
        assertTrue(true);
    }

    @Nested
    class InnerExampleTest {
        @Test
        void innerTest() {
            assertTrue(true);
        }
    }
}

Expected Result

One TEST-ExampleTest.xml file containing the results of both tests or two files ({}TEST-ExampleTest.xml{} and {}TEST-ExampleTest$InnerExampleTest.xml{}) containing the results of their tests.

Actual Result

  • TEST-ExampleTest.xml does not contain any test case.
  • TEST-ExampleTest$InnerExampleTest.xml contains results for both test cases.

Workaround

Do not put any tests into the parent class if nested classes are used.

Analysis

org.apache.maven.surefire.junitplatform.RunListenerAdapter does not distinguish between the parent and the nested classes. Both are reported as new test sets.

org.apache.maven.plugin.surefire.report.TestSetRunListener does not support nested test sets, so the test set of the nested class overrides the test set of the parent class.


Affects: 3.1.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingpriority:minorMinor loss of function, or other problem where easy workaround is present

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions