Reputation: 159
Before I place my question, I must confess that I am a total newbie to both Java and Spring and hence my question may sound completely nonsensical. I have a Spring based Java application and my job is to write integration/acceptance tests for it. Now when I scanned through the project structure I could see that there are multiple Beans spread across different modules which I will need to instantiate to build my test case. A quick look through Spring tutorials also told me that I have to load the Application Context xml before doing any meaningful work with the beans. So, I loaded the Application Context XML of the module that I wanted to test. But when I execute the test, Spring complains that it was not able to locate a bunch of other beans. Now, I know that these "bunch" of beans are there in other modules with their wiring information in some other Application Context xml files. My question is, in a Spring project
Would there be a parent level Application Context xml file that I should be loading instead of module specific ones?
Is it possible that I create an Application Context xml for my test project and import all the other Application Context xmls inside that?
Any other solution...
Any help is highly appreciated :)
Upvotes: 0
Views: 454
Reputation: 193
Well, it depends on which layer you would want to test. Let me try to answer your question with an example: Say, you have a Service and a DAO and you would want to test the DAO layer, you would only load the dao.xml and wire in your test specific beans in tests.xml (if any). So, effectively your tests.xml would contain
<beans> <import resource ="dao.xml"/> <bean id="abstractTest" class="com.something.AbstractTest"/> </beans>
and you would run ur test with a SpringJUnit4ClassRunner mentioning tests.xml as your ContextConfiguration.
Upvotes: 1