Uploaded image for project: 'Maven Surefire'
  1. Maven Surefire
  2. SUREFIRE-2194

JUnit 5: Implementing tests in test class and nested class results in incorrect reporting

    XMLWordPrintableJSON

Details

    Description

      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.

      Attachments

        Activity

          People

            Unassigned Unassigned
            jochen-kraushaar Jochen Kraushaar
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated: