简体   繁体   中英

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.

  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();
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM