Skip to content

Annotation configuration based TestContext [SPR-6567] #11233

Closed

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

Activity

  1. spring-projects-issues commented on Dec 15, 2009

    @spring-projects-issues
    CollaboratorAuthor

    Keesun Baik commented

    These are implementation and test.

  2. spring-projects-issues commented on Dec 15, 2009

    @spring-projects-issues
    CollaboratorAuthor

    Keesun Baik commented

    These are sample test and configuration.

  3. spring-projects-issues commented on Aug 24, 2010

    @spring-projects-issues
    CollaboratorAuthor

    Chris Beams commented

    Duplicates #10852

  4. added
    in: test
    type: enhancement
    status: duplicate
    on Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    in: teststatus: duplicatetype: enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions