Description
Keesun Baik opened SPR-6567 and commented
Why don't you add AnnotationContextLoader that supports annotation configuration based TestContext.
for example. If there is an annotation configuration like this
@Configuration
public class SpringAnnotationConfigTestAppConfig {
@Bean
public String name(){
return "keesun";
}
}
and, at the same package, I can make test like this.
@RunWith
(SpringJUnit4ClassRunner.class)
@ContextConfiguration
(loader = AnnotationContextLoader.class, locations = {"."})
public class SpringAnnotationConfigTest {
@Autowired ApplicationContext ac;
@Autowired String name;
@Test
public void di(){
assertNotNull(ac);
assertThat(name, is("keesun"));
}
}
then, conventionally SpringJUnit4ClassRunner finds SpringAnnotationConfigTest + "AppConfig.java" for an annotation configuration.
Of course, It makes sence that we sould use 'locations' attribute of @ContextConfigruation
like these.
@ContextConfiguration
(loader = AnnotationContextLoader.class, locations = {"/sandbox/springtest/sample/SpringAnnotationConfigTestAppConfig.java"})
@ContextConfiguration
(loader = AnnotationContextLoader.class, locations = {"/sandbox/springtest/sample/"})
@ContextConfiguration
(loader = AnnotationContextLoader.class, locations = {"/sandbox/springtest/sample"})
@ContextConfiguration
(loader = AnnotationContextLoader.class, locations = {"./SpringAnnotationConfigTestAppConfig.java"})
@ContextConfiguration
(loader = AnnotationContextLoader.class, locations = {"./"})
@ContextConfiguration
(loader = AnnotationContextLoader.class, locations = {"."})
with '.Java' locations can be used to AnnotationConfigurationApplicationContext.regist(), and without '.java' locations will be used to AnnotationConfigurationApplicationContext.scan().
What do you think about this?
Affects: 3.0 RC3
Attachments:
- AnnotationContextLoader.java (5.89 kB)
- AnnotationContextLoaderTest.java (1.95 kB)
- SpringAnnotationConfigTest.java (1.61 kB)
- SpringAnnotationConfigTestAppConfig.java (476 bytes)
Issue Links:
- Provide TestContext support for @Configuration classes [SPR-6184] #10852 Provide TestContext support for
@Configuration
classes ("duplicates")
3 votes, 5 watchers