使用StrutsSpringTestCase进行单元测试,怎么自定义struts.xml位置?

J2EE 码拜 9年前 (2015-04-06) 1289次浏览 0个评论

我来描述一下我遇到的问题,有点长:
前几天项目负责人提出了一个要求,要求Action是可以进行单元测试的,之前没有弄过这个,于是上网搜吧,遂即发现了Struts提供了一种测试方案,也就是继承StrutsSpringTestCase这个类,然后写单元测试.
因为项目struts与spring集成,并且applicaContext.xml和struts.xml没有放在src下,而是放在了src/config下,所以当我真正开始测试时发生了问题.
问题1:spring找不到applicaContext.xml文件.
问题2:找不到struts.xml文件

问题1我已经解决了,是自己写了一个类,继承了StrutsSpringTestCase,重写了里面的getContextLocation方法,但是问题2我始终解决不了,因为它使用了MockHttpServletRequest,并没有读取web.xml,我在web.xml里配置的struts.xml的位置也就随之失效了.

使用StrutsSpringTestCase进行单元测试,怎么自定义struts.xml位置?
40分
web.xml  里面引入:
<context-param>
<param-name>contextConfigLocation</param-name>
//看看classes 目录下struts文件路径
<param-value>/WEB-INF/classes/config/struts*.xml</param-value>
</context-param>
使用StrutsSpringTestCase进行单元测试,怎么自定义struts.xml位置?
引用 1 楼 HeiBoyYang 的回复:

web.xml  里面引入:
<context-param>
<param-name>contextConfigLocation</param-name>
//看看classes 目录下struts文件路径
<param-value>/WEB-INF/classes/config/struts*.xml</param-value>
</context-param>

1.它没有读取web.xml   我在web.xml定义了Struts.xml的位置,可是没有生效
2.我尝试用applicationContext = new FileSystemXmlApplicationContext(
     “classpath:config/spring/applicationContext.xml”,
     “WEB-INF/config/spring/applicationContext.xml”,
     “WEB-INF/config/spring/applicationContext*.xml”,
     “classpath:config/struts/struts.xml”);
方式定义,仍然ActionMapping mapping = getActionMapping(“xxx”);时获取到了null


CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明使用StrutsSpringTestCase进行单元测试,怎么自定义struts.xml位置?
喜欢 (0)
[1034331897@qq.com]
分享 (0)

文章评论已关闭!