Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Annotation configuration based TestContext [SPR-6567] #11233

Closed
spring-issuemaster opened this issue Dec 15, 2009 · 3 comments
Closed

Annotation configuration based TestContext [SPR-6567] #11233

spring-issuemaster opened this issue Dec 15, 2009 · 3 comments

Comments

@spring-issuemaster
Copy link
Collaborator

@spring-issuemaster spring-issuemaster commented Dec 15, 2009

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:

  • #10852 Provide TestContext support for @Configuration classes ("duplicates")

3 votes, 5 watchers

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Dec 15, 2009

Keesun Baik commented

These are implementation and test.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Dec 15, 2009

Keesun Baik commented

These are sample test and configuration.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Aug 24, 2010

Chris Beams commented

Duplicates #10852

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant
You can’t perform that action at this time.