-
Notifications
You must be signed in to change notification settings - Fork 38.6k
Open
Labels
in: testIssues in the test moduleIssues in the test modulestatus: waiting-for-triageAn issue we've not yet triaged or decided onAn issue we've not yet triaged or decided on
Description
In the snippet below, the ServiceB
MockBean
is not reset between firstTest
and secondTest
, but it should be. This causes secondTest
to fail on verify(serviceB).bar();
, as there are 2 invocations instead of just the expected 1.
Note that the @Import(ServiceC.class)
on ChildTest
is not required for the test as such, but causes (by some mysterious means) the failure to reset ServiceB
, as removing the @Import
will make the test pass.
Spring Boot version is 3.4.5.
This issue may be related to spring-projects/spring-boot#12470.
Services
@Component
public class ServiceA {
@Autowired
public ServiceB serviceB;
public void foo() {
serviceB.bar();
}
}
@Component
public class ServiceB {
public void bar() {
}
}
@Component
public class ServiceC {
}
Test
@SpringBootTest
public abstract class ParentTest {
@MockBean
ServiceB serviceB;
@Autowired
ServiceA serviceA;
@Nested
class NestedTest {
@Test
void firstTest() {
serviceA.foo();
verify(serviceB).bar();
}
@Test
void secondTest() {
serviceA.foo();
verify(serviceB).bar();
}
}
}
@Import(ServiceC.class)
public class ChildTest extends ParentTest {
}
Metadata
Metadata
Assignees
Labels
in: testIssues in the test moduleIssues in the test modulestatus: waiting-for-triageAn issue we've not yet triaged or decided onAn issue we've not yet triaged or decided on