I would like to learn why inner beans are not created while trying to test like below :
RunWith(SpringRunner.class)
@SpringBootTest(classes=MyTest.class)
public class MyTest {
@SpyBean A a;
@Test
public void myTest() {
assertTrue(a.some());
}
@Component
class A {
private B b;
A(B dependency) {
this.b = dependency;
}
boolean some() {
return b.value();
}
}
@Configuration
class B {
boolean value() { return true; }
}
}
Error: No qualifying bean of type 'com.example.MyTest$B' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations:
Despite annotating the inner class with @Configuration it is not creating the bean while testing the method.
please note it works when I add like below @SpringBootTest(classes=MyTest.class,MyTest.B.class,MyTest.A.class})