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

TestContext/ContextConfiguration: inherit loader, not just locations. [SPR-5916] #10585

Closed
spring-projects-issues opened this issue Jul 10, 2009 · 4 comments
Assignees
Labels
in: test Issues in the test module type: enhancement A general enhancement
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

Jason Novak opened SPR-5916 and commented

TestContext supports inheritance of @ContextConfiguration's "locations", but not "loader". This is unfortunate because I use a special ContextLoader to override bean definitions.

Suppose I have 2 test classes:

@ContextConfiguration(loader = FooContextLoader.class, locations = { "Parent.xml" })
public abstract class AbstractParentTest { ... };

@ContextConfiguration // implicitly loads default location.
public class ConcreteChildTest extends AbstractParentTest { ... };

I want ConcreteChildTest to load beans from both Parent.xml and the default location(s), and inherit the ContextLoader from AbstractParentTest.

If I specify a custom loader in AbstractParentTest, it only takes effect if I remove the @ContextConfiguration attribute from ConcreteChildTest.

But if I remove the @ContextConfiguration attribute from ConcreteChildTest, Spring will only load beans from Parent.xml, ignoring the child's default location. =)


Affects: 2.5.6

Referenced from: commits fc79d98, b2c723a, ba27c29

@spring-projects-issues
Copy link
Collaborator Author

Sam Brannen commented

Thanks for pointing this out Jason.

ContextLoader class is now inherited from class hierarchy if not specified explicitly via @ContextConfiguration's loader attribute on the current test class.

@spring-projects-issues
Copy link
Collaborator Author

Marek Hudik commented

@ContextConfiration gets not inherited.

I have abstract test defined like:

@ContextConfiguration(loader = WebTestContextLoader.class, locations = { "classpath:spring-test-application.xml"})
public abstract class AbstractServletTest extends AbstractTransactionalTestNGSpringContextTests {
...

and it's child

public class TradeImportServletTest extends AbstractServletTest {
...

In this case (no @ContextConfiguration annotation) a loader is not inherited.

The same happens for following definition

@ContextConfiguration
public class TradeImportServletTest extends AbstractServletTest {
...

It works only if I repeat ContextConfiguration in child class like:

@ContextConfiguration(loader = WebTestContextLoader.class, locations = { "classpath:spring-test-application.xml"})
public class TradeImportServletTest extends AbstractServletTest {

@spring-projects-issues
Copy link
Collaborator Author

Marek Hudik commented

I use Spring 3.0.5.RELEASE.

@spring-projects-issues
Copy link
Collaborator Author

Chris Beams commented

Marek, if you're still seeing this behavior against the latest version of Spring (3.1.1 or 3.2.0.M1 at time of writing), please log a new issue against the Test component and mention this issue ID when doing so. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: test Issues in the test module type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants