There is a doc http://static.springsource.org/spring/docs/2.5.6/reference/testing.html how to add IoC support to junit tests using xml-configuration, but I can not find example for java-based configuration…
For example, I have java-based bean:
public class AppConfig
{
@Bean
public Test getTest() { return new Test(); }
}
And test:
@RunWith(SpringJUnit4ClassRunner.class)
public class IocTest
{
@Autowired
private Test test;
@Test
public void testIoc()
{
Assert.assertNotNull(test);
}
}
What should I add to enable java-based beans to my junit test without using xml-configs?
Normally I use:
new AnnotationConfigApplicationContext(AppConfig.class);
but it does not work for tests…
Update: Spring 3.1 will support it out of the box, see Spring 3.1 M2: Testing with @Configuration Classes and Profiles.
It seems to be this feature is not supported by Spring yet.
However, it can be easily implemented:
–
–