permaculture playing cards*
The moose likes Testing and the fly likes How to prevent spring from loading context when running an struts 1 action through junit Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Testing
Bookmark "How to prevent spring from loading context when running an struts 1 action through junit" Watch "How to prevent spring from loading context when running an struts 1 action through junit" New topic
Author

How to prevent spring from loading context when running an struts 1 action through junit

r vertet
Greenhorn

Joined: Apr 10, 2012
Posts: 17
Hi,

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?
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30116
    
150

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.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
r vertet
Greenhorn

Joined: Apr 10, 2012
Posts: 17
Thank you Jeanne,

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)
 
wood burning stoves
 
subject: How to prevent spring from loading context when running an struts 1 action through junit
 
Similar Threads
Test cases
URL not getting through to servlet
How to prevent spring from loading context when running an action through junit
Strange exception with StrutsTestCase for JUnit
JUnit - Testing someone elses code