✕
Skip to content

Can not select JUnit Jupiters inner parameterized class test #3548

Open

Description

@mpkorstanje

Affected version

3.6.1

Bug description

Given the following JUnit Jupiter v6.1.3 test:

package com.example.project;

import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.Parameter;
import org.junit.jupiter.params.ParameterizedClass;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;

@ParameterizedClass
@ValueSource(ints = { 1, 2 })
class CalculatorParameterizedClassTests {

	@Parameter
	int i;

	@ParameterizedTest
	@ValueSource(ints = { 1, 2 })
	void parameterizedTest(int j) {

	}

	@Nested
	@ParameterizedClass
	@ValueSource(ints = { 1, 2 })
	class Inner {

		final int j;

		Inner(int j) {
			this.j = j;
		}

		@Test
		void regularTest() {

		}
	}
}

When running the regularTest with Surefire 3.6.0

mvn test -D'test=CalculatorParameterizedClassTests$Inner#regularTest'

Surefire will execute 4 tests:

[INFO] --- surefire:3.6.0:test (default-test) @ junit-jupiter-starter-maven ---
[INFO] Using auto detected provider org.apache.maven.surefire.junitplatform.JUnitPlatformProvider
[INFO] 
[INFO] -------------------------------------------------------
[INFO]  T E S T S
[INFO] -------------------------------------------------------
...
[INFO] 
[INFO] Results:
[INFO] 
[INFO] Tests run: 4, Failures: 0, Errors: 0, Skipped: 0
[INFO] 
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  1.055 s
[INFO] Finished at: 2026-10-26T13:27:59+01:00
[INFO] ------------------------------------------------------------------------

When ran with Surefire 3.6.1, no tests are executed.

[INFO] --- surefire:3.6.1:test (default-test) @ junit-jupiter-starter-maven ---
[INFO] Using auto detected provider org.apache.maven.surefire.junitplatform.JUnitPlatformProvider
[INFO] 
[INFO] -------------------------------------------------------
[INFO]  T E S T S
[INFO] -------------------------------------------------------
[INFO] 
[INFO] Results:
[INFO] 
[INFO] Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
[INFO] 
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  0.926 s
[INFO] Finished at: 2026-10-26T13:27:46+01:00
[INFO] ------------------------------------------------------------------------

Looking at the changes made to the TestPlanScannerFilter in a35e23b there seems to be a misunderstanding. The collectClassNames method assumes that all candidates will be in the test plan if they're discovered. This is not necessarily the case. They may be registered dynamically by one of their parent containers.

Activity

  1. mpkorstanje commented on Oct 26, 2026

    @mpkorstanje
    ContributorAuthor

    Moreover, Surefire 3.6.1 also doesn't warn that no tests could be found as it would when trying to select the non-existent NoSuchClass inner class:

    mvn test -D'test=CalculatorParameterizedClassTests$NoSuchClass#regularTest'
    [INFO] --- surefire:3.6.1:test (default-test) @ junit-jupiter-starter-maven ---
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD FAILURE
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time:  0.416 s
    [INFO] Finished at: 2026-10-26T13:41:38+01:00
    [INFO] ------------------------------------------------------------------------
    [ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:3.6.1:test (default-test) on project junit-jupiter-starter-maven: No tests matching pattern "CalculatorParameterizedClassTests$NoSuchClass#regularTest" were executed! (Set -Dsurefire.failIfNoSpecifiedTests=false to ignore this error.) -> [Help 1]
    
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

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions