Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DisplayNameGenerator cannot access runtime enclosing type for @Nested test class #4130

Open
1 task
sbrannen opened this issue Nov 15, 2024 · 0 comments
Open
1 task

Comments

@sbrannen
Copy link
Member

sbrannen commented Nov 15, 2024

Overview

A DisplayNameGenerator can access the type of a @Nested test class as well as the enclosing class in which a @Nested test class is declared, but it cannot access the concrete type of the enclosing instance for a @Nested test class.

When a DisplayNameGenerator is used to build hierarchical display names, this can lead to confusing results or even conflicting results depending on the structure of the test classes used, "conflicting" in the sense that two nested test classes may have identical display names that do not represent the runtime structure of the test classes.

Example

@IndicativeSentencesGeneration
abstract class AbstractBaseTests {

	@Nested
	class NestedTests {

		@Test
		void test() {
		}
	}
}
class ScenarioOneTests extends AbstractBaseTests {
}
class ScenarioTwoTests extends AbstractBaseTests {
}

Actual Behavior

When running ScenarioOneTests and ScenarioTwoTests, we currently see the following display names.

  • ScenarioOneTests
    • AbstractBaseTests, NestedTests
      • AbstractBaseTests, NestedTests, test()
  • ScenarioTwoTests
    • AbstractBaseTests, NestedTests
      • AbstractBaseTests, NestedTests, test()

Expected Behavior

When running ScenarioOneTests and ScenarioTwoTests, we would expect the following display names.

  • ScenarioOneTests
    • ScenarioOneTests, NestedTests
      • ScenarioOneTests, NestedTests, test()
  • ScenarioTwoTests
    • ScenarioTwoTests, NestedTests
      • ScenarioTwoTests, NestedTests, test()

Related Issues

Deliverables

  • Ensure that a DisplayNameGenerator can access the concrete type of the enclosing instance for a @Nested test class.
@sbrannen sbrannen added this to the 5.12 M1 milestone Nov 15, 2024
@sbrannen sbrannen changed the title DisplayNameGenerator cannot access type of enclosing instance for @Nested test class DisplayNameGenerator cannot access runtime enclosing type for @Nested test class Nov 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant