Bahij.Mik
Bahij.Mik

Reputation: 1484

Testing struts 2 actions

Guys what is the best way to test struts actions? Is there any framework someone can recommend? I just recently started working with struts, I used to use mockito for spring mvc testing, but I can't find any good source online, most of them are way too outdated.

Upvotes: 0

Views: 306

Answers (1)

Amit kumar
Amit kumar

Reputation: 2694

  1. Add a new StrutsXmlConfigurationProvider for each config file you want to add.
  2. Override the StrutsTestCase setUp method.
  3. If you have multiple actions in your project, create a base test class that extends StrutsTestCase and just have all your action tests extend that.

Refer to this sample implementation:

@Override
public void setUp() throws Exception {
    super.setUp();
    List<ContainerProvider> providers = super.configurationManager.getContainerProviders();
    //make one of these for each config file you want to add
    StrutsXmlConfigurationProvider newConfig = new StrutsXmlConfigurationProvider("src/main/webapp/WEB-INF/classes/struts.xml", true, super.servletContext);
    providers.add(newConfig);
    super.configurationManager.reload();
}

Upvotes: 1

Related Questions