Env: Struts 1.3, Spring 2.5, Junit 4.10 and StrutsTestcase 2.1.4; Spring context is loaded via org.springframework.web.struts.ContextLoaderPlugIn in the struts-config.
I have a junit-test that tests my action. Because of the ContextLoaderPlugin the full spring context is loaded which makes running the unit-test rather slow. Beside I don't need the full context because, as a good practice, I mock any required backend-classes.
How can I prevent Spring from loading the full context?
Spring chooses to load the context by the superclass or annotation (depending on what version of JUnit you are on.) You can still run non-Spring based tests in JUnit against Spring code. You just have to inject anything you need by yourself.
the problem I face here is that the MockStrutsTestCase reads the web.xml and struts-config.xml and in this config I tell ContextLoaderPlugIn which classes to load when starting (because this is needed inside the container).
But when running the struts-action through Junit I want, as you say rightly, set up my context by hand (and thus ignore the context from struts-config.xml)
subject: How to prevent spring from loading context when running an struts 1 action through junit