We are using SpringBootTest for Integration testing.
Let us say for example that we have a class : ClassWithManyConstructorArgs with one Required Constructor Argument (another class, DependencyA) and no default constructor.
Example : public ClassWithManyConstructorArgs(DependencyA a){ }
Our Integration test is configured as :
@SpringBootTest ( classes = [ClassWithManyConstructorArgs::class] )
I need to provide mocked implementations of the DependencyA class. How can I do that? What is the syntax to tell the system to initialize the ClassWithManyConstructorArgs using mocked DependencyA object?
Assume we have two beans: ServiceA and ServiceB.
ServiceA depends on ServiceB. for testing,
@SpringBootTest(classes = {ServiceA.class})
).here's the code:
@SpringBootTest(classes = {ServiceA.class})
public class ServiceATest {
@MockBean
private ServiceB serviceB;
@Autowired
private ServiceA serviceA;
@Test
void testMethodA() {
serviceA.methodA();
}
}