|
这个是测试用例:
package com.gpy.oa.admin.identity.action;
import org.apache.struts2.StrutsJUnit4TestCase;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.opensymphony.xwork2.ActionProxy;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"file:D:/ws2014/oa/WebContent/WEB-INF/applicationContext*.xml"})
public class JobTestAction extends StrutsJUnit4TestCase<JobAction> {
@Test
public void selectJobs(){
ActionProxy ap = this.getActionProxy("/admin/identity/selectJob.action");
Assert.assertNotNull(ap);
}
}
以JUnit运行时报错,说我在web.xml里面没有配置Spring控制器的<listener-class>没有配置,信息如下 web.xml中关于Spring的配置如下: <!-- 配置Spring核心监听器 --> <context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/applicationContext*.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> PS:我整个架构完成后,请求→Action→Service→DAO 这个流程是完全通畅的。所以对于测试用例这里报错,求教大神。 |
|
![]() 40分 |
<!-- 配置Spring核心监听器 --> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/applicationContext*.xml</param-value> </context-param> 调换一下位置 |
![]() |
listener要配置在最前面
|
![]() |
楼上的方法试试。
|
![]() |
应该是顺序不对,还有注意一下路径,建议你放到src下面:
classpath:applicationContext*.xml |
![]() |
我最开始就是先listener,再param的,一样的报错。 |
![]() |
你测试的时候,没有去web.xml读取监听器,才会报呢样的错
|
![]() |
那该怎么写呢?第一次写测试用例,什么都不懂! |
![]() |
测试类继承StrutsSpringTestCase试试
|

