Skip to content

Direct selection of JUnit Jupiter @Nested class runs no tests since 3.6.0-M1 #3446

Description

@wilx

Affected version

3.6.0-M1 and 3.6.0-M2-SNAPSHOT (b2e1f70b2). The same test works with 3.5.4.

Bug description

Selecting a non-static JUnit Jupiter @Nested test class directly by its JVM binary name runs no tests since Surefire 3.6.0-M1. Maven exits successfully and produces no test report.

Given:

package example;

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

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

class OuterTest {
    private boolean outerSetUp;

    @BeforeEach
    void setUpOuter() {
        outerSetUp = true;
    }

    @Nested
    class Selected {
        @Test
        void selectedTest() {
            assertTrue(outerSetUp);
        }
    }
}

Run the test using the quoted binary name so that the shell does not expand $Selected:

mvn -Dtest='example.OuterTest$Selected' test

Expected: selectedTest runs, including the enclosing @BeforeEach lifecycle callback.

Actual with 3.6.0-M1 and current master: zero tests run, Maven exits successfully, and no Surefire report is produced.

With Surefire 3.5.4, the same command executes the selected nested test as expected. Direct selection of a static nested class also still works on current master, so this is specific to the enclosing hierarchy required by a non-static @Nested class.

JUnit documents that nested tests can be run independently while lifecycle setup from enclosing classes is still executed:
https://docs.junit.org/5.14.4/writing-tests/nested-tests.html

Related issues:

This appears to be a regression from the provider-level class-name filtering added in #3179. JUnit represents a non-static nested selection with its enclosing hierarchy, and the exact nested-class include appears to reject the enclosing class descriptor.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions