环境描述:Struts2 + Spring2.5 + hibernate3 + junit4
目的:对后台Action层的函数进行单元测试
需要的Jar包:junit4.jar(eclipse自带的,在项目路径中导入即可。“properties->Add Library->JUnit->JUnit4”) struts2-junit-plugin-2.1.8.jar spring-test.jar
public class UserAction_Junit extends StrutsSpringTestCase {
protected String getContextLocations() {
return "classpath*:beans*.xml";
}
@Test
public void testGetUsers() throws Exception {
String result = executeAction("/user!getUsers.action");
System.out.println(result);
}
}