Reputation: 2396
I have a bean that describes my session factory. I only want to load this bean once throughout my entire test suite. I wanted to know, is this possible? And I would like to localize to my context.xml
if that is possible too. I can post any source you want, just ask.
Thanks in advance!
Upvotes: 0
Views: 548
Reputation: 340933
In Spring test framework, if all test case classes use the same locations
attribute, the context is preserved between runs. In the example below context defined in context.xml
will be loaded only once (before first test case) and will be closed when JVM exits:
@ContextConfiguration(locations = "classpath:context.xml")
@Transactional
public class FooTest {
//...
}
@ContextConfiguration(locations = "classpath:context.xml")
@Transactional
public class BarTest {
//...
}
You cannot preserve only one bean, but you can load the whole context once. See my article Speeding up Spring integration tests.
Upvotes: 3