天天看點

Struts2+Hibernate+Spring 測試類的書寫方法

public class LoginActionTest extends TestCase { private ApplicationContext ctx; private ActionContext context; private LoginAction loginAction; private GoodUserBIZ userbiz; @Before public void setUp() throws Exception { super.setUp(); this.ctx = new FileSystemXmlApplicationContext(new String[] { "WebRoot/WEB-INF/classes/applicationContext.xml", "src/com/shopping/pojo/Good_user.hbm.xml" }); this.userbiz = (GoodUserBIZ) this.ctx.getBean("GoodUserBIZ"); this.loginAction = new LoginAction(); this.context = ActionContext.getContext(); } @After public void tearDown() throws Exception { if (this.context != null) { this.context = null; } if (this.ctx != null) { this.ctx = null; } } @Test public void testCheckUser() { this.loginAction.setGoodUserBiz(this.userbiz); String result = this.loginAction.checkUser("hongboliu", "a123"); assertEquals("login_success", result); } }