環境描述: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);
}
}