views:

163

answers:

1

I am using AbstractTransactionalSpringContextTests to run spring integrations tests. The spring context is loaded just once and then all the tests are run. How do I do the same if I want my tests to be in many classes and packages.

Of course, the spring context should be loaded just once for all my tests (in all classes and packages), and not once per class or package.

+1  A: 

As the Javadocs for AbstractSingleSpringContextTests (one of the superclasses of AbstractTransactionalSpringContextTests) state:

This class will cache contexts based on a context key: normally the config locations String array describing the Spring resource descriptors making up the context. Unless the setDirty() method is called by a test, the context will not be reloaded, even across different subclasses of this test. This is particularly beneficial if your context is slow to construct, for example if you are using Hibernate and the time taken to load the mappings is an issue.

Your context is cached, so all other tests that run within the same classloader (i.e. - all your other tests that run during the same test run) will use the cached context. You don't need to do any extra setup - should be done for you already. If you're not sure about this, or wish to troubleshoot, simply turn on the logging for org.springframework and you should see plenty of helpful logging about when the context is being loaded, which file, how; etc.

matt b