Skip to content

@MockitoBeanSettings is not inherited in @Nested test class #33685

@sbrannen

Description

@sbrannen

In the following example, the unnecessaryStub() test method in NestedTests should succeed since it should inherit the Strictness.LENIENT configuration from its enclosing class; however, it currently fails with an UnnecessaryStubbingException because the default Strictness.STRICT_STUBS is used.

@SpringJUnitConfig
@MockitoBeanSettings(Strictness.LENIENT)
class InheritedStrictnessTests {

	@Nested
	class NestedTests {

		@Test
		void unnecessaryStub() {
			List list = mock();
			when(list.get(anyInt())).thenReturn(new Object());
		}
	}

	@Configuration
	static class Config {
		// no beans
	}

}

Metadata

Metadata

Assignees

Labels

in: testIssues in the test moduletype: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions