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

Junit 5 @Nested Tests executes when excluded

    XMLWordPrintableJSON

Details

    Description

      Test classes with the Junit 5 `@Nested` annotation is executed even when explicitly excluded with the `<exclude>` tag.

      Minimal reproducing example

      https://github.com/Steinstark/surefire-issue see the IssueTest.

      Surefire configuration

      <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-surefire-plugin</artifactId>
          <version>3.0.0-M6</version>
          <configuration>
              <excludes>
                  <exclude>**/IssueTest$NestedTests</exclude>
              </excludes>
          </configuration>
      </plugin>

      Expected behavior

      The tests inside the `@Nested` excluded class is not run.

      Actual behavior

      The tests inside the `@Nested` excluded class is run.

      Additional info

      I believe the problem is caused by only setting the selectors based on the exact classes surefire is expected to run for the LauncherDiscoveryRequestBuilder in JunitPlatformProvider but as far as I can tell Junit will by default discover `@Nested` classes aswell from the selectors.

      The solution is probably to provide a filter in addition to the selector. Not sure if it is a good solution but locally I changed the newFilters method to always add the TestMethodFilter and it appear to have worked. Might be something worth looking further into at least.

      Attachments

        Activity

          People

            Unassigned Unassigned
            steinstark Henrik Josefsson
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: