Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
r vertet
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
author & internet detective
Marshal
Posts: 34973
379
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
r vertet
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic