If you're using AbstractDependencyInjectionSpringContextTests, you can override its getConfigLocations() method so that it returns :- the real config file(s) for the tier(s) you want to test
- fake config files for the tiers you want to mock or replace with test versions (e.g. a test database that could even be an in-memory one)
The other approach I've used is to load the lower-tier stubs/mocks into a StaticApplicationContext, then use that as the parent context for a FileSystemXmlApplicationContext that uses the real config files for the layer you're testing. Here's what I mean:
Code:
// Create a static application context to contain the mocks
StaticApplicationContext staticApplicationContext = new StaticApplicationContext();
// Create the mocks and register them with this application context
Foo mockFoo = createNiceMock(Foo.class);
staticApplicationContext.getBeanFactory().registerSingleton("foo", mockFoo);
staticApplicationContext.refresh();
// Make a new context based on the one containing the mocks, using the wiring information contained in the live XML files for the tier under test
String[] configFileNames = ... ;
ApplicationContext applicationContext = new FileSystemXmlApplicationContext(configFileNames, staticApplicationContext);
// Get beans from the "applicationContext" and test them as desired
...
HTH,