Skip to content

Annotation configuration based TestContext [SPR-6567] #11233

Closed
@spring-projects-issues

Description

@spring-projects-issues

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:

Issue Links:

3 votes, 5 watchers

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions