單元測試與Spring整合的struts2中的action

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

}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章