TestCactusLoginAction .java
// StrutsTestCase - a JUnit extension for testing Struts actions
// within the context of the ActionServlet.
// Copyright (C) 2002 Deryl Seale
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the Apache Software License as
// published by the Apache Software Foundation; either version 1.1
// of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// Apache Software Foundation Licens for more details.
//
// You may view the full text here: http://www.apache.org/LICENSE.txt
package examples.cactus;
import java.io.File;
import servletunit.struts.CactusStrutsTestCase;
public class TestCactusLoginAction extends CactusStrutsTestCase {
public TestCactusLoginAction(String testName) {
super(testName);
}
public void setUp() throws Exception {
super.setUp();
setInitParameter("validating", "false"); //添加
this.setConfigFile("/WEB-INF/struts-config.xml");//添加
}
public void testSuccessfulLogin() {
addRequestParameter("username", "deryl");
addRequestParameter("password", "radar");
setRequestPathInfo("/login");
actionPerform();
verifyForward("success");
verifyForwardPath("/main/success.jsp");
assertEquals("deryl", getSession().getAttribute("authentication"));
verifyNoActionErrors();
}
public void testFailedLogin() {
setConfigFile("/WEB-INF/struts-config.xml");
addRequestParameter("username", "deryl");
addRequestParameter("password", "express");
setRequestPathInfo("/login.do");
actionPerform();
verifyForward("login");
verifyForwardPath("/login/login.jsp");
verifyInputForward();
verifyActionErrors(new String[] { "error.password.mismatch" });
assertNull(getSession().getAttribute("authentication"));
}
public static void main(String[] args) {
junit.textui.TestRunner.run(TestCactusLoginAction.class);
}
}
MockStrutsTestCase
// StrutsTestCase - a JUnit extension for testing Struts actions
// within the context of the ActionServlet.
// Copyright (C) 2002 Deryl Seale
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the Apache Software License as
// published by the Apache Software Foundation; either version 1.1
// of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// Apache Software Foundation Licens for more details.
//
// You may view the full text here: http://www.apache.org/LICENSE.txt
package examples;
import java.io.File;
import servletunit.struts.MockStrutsTestCase;
public class TestLoginAction extends MockStrutsTestCase {
public TestLoginAction(String testName) {
super(testName);
}
public void setUp() throws Exception {
super.setUp();
setInitParameter("validating", "false");
//找到WebRoot和配置文件
setContextDirectory(new File("WebRoot"));
this.setConfigFile("/WEB-INF/struts-config.xml");
}
public void testSuccessfulLogin() {
setRequestPathInfo("/login");
addRequestParameter("username", "deryl");
addRequestParameter("password", "radar");
actionPerform();
verifyForward("success");
assertEquals("deryl", (String) getSession().getAttribute(
"authentication"));
verifyNoActionErrors();
}
public void testFailedLogin() {
setConfigFile("/WEB-INF/struts-config.xml");
addRequestParameter("username", "deryl");
addRequestParameter("password", "express");
setRequestPathInfo("/login");
actionPerform();
verifyForward("login");
verifyForwardPath("/login/login.jsp");
verifyInputForward();
verifyActionErrors(new String[] { "error.password.mismatch" });
assertNull(getSession().getAttribute("authentication"));
}
public static void main(String[] args) {
junit.textui.TestRunner.run(TestLoginAction.class);
}
}
分享到:
相关推荐
StrutsTestCase工程例子,很实用!
strutsTestCase所需要用到的jar org.springframework.core-3.1.2.RELEASE.jar spring-test.jar struts2-junit-plugin-2.3.16.3.jar xmlbeans-2.3.0.jar xmlpull-1.1.3.1.jar xstream-1.4.2.jar xwork-core-2.3.16.3....
StrutsTestCase-2.1.4(含文档、源码、官方示例).rar
Struts是目前非常流行的基于MVC的Java Web框架。...第19章到第21章介绍了如何采用第三方软件,如Apache Common Logging API、Log4J、ANT和StrutsTestCase,来控制Struts应用的输出日志、管理以及测试Struts应用项目。
内容推荐 Struts是目前非常流行的基于MVC的Java ...第19章到第21章介绍了如何采用第三方软件,如Apache Common Logging API、Log4J、ANT和StrutsTestCase,来控制Struts应用的输出日志、管理以及测试Struts应用项目。
Struts是目前非常流行的基于MVC的Java Web框架。...第19章到第21章介绍了如何采用第三方软件,如Apache Common Logging API、Log4J、ANT和StrutsTestCase,来控制Struts应用的输出日志、管理以及测试Struts应用项目。
Struts是目前非常流行的基于MVC的Java Web框架。...第19章到第21章介绍了如何采用第三方软件,如Apache Common Logging API、Log4J、ANT和StrutsTestCase,来控制Struts应用的输出日志、管理以及测试Struts应用项目。
Struts是目前非常流行的基于MVC的Java Web框架。...第19章到第21章介绍了如何采用第三方软件,如Apache Common Logging API、Log4J、ANT和StrutsTestCase,来控制Struts应用的输出日志、管理以及测试Struts应用项目。
Struts是目前非常流行的基于MVC的Java Web框架。...第19章到第21章介绍了如何采用第三方软件,如Apache Common Logging API、Log4J、ANT和StrutsTestCase,来控制Struts应用的输出日志、管理以及测试Struts应用项目。
第19章到第21章介绍了如何采用第三方软件,如Apache Common Logging API、Log4J、ANT和StrutsTestCase,来控制Struts应用的输出日志、管理以及测试Struts应用项目。 这个真的是包含所有的源码。。。
b、ActionForms使用不便、无法进行单元测试(StrutsTestCase只能用于集成) Struts提供了几个标签库?都是什么标签库? Struts提供了五个标签库,即:HTML、Bean、Logic、Template和Nested。 HTML 标签 用来创建能够...
struts2-junit-plugin-2.1.6.jar struts2测试 action测试 strutstestcase
用DbUnit进行测试反复测试StrutsStruts的集成测试虽然Struts正在慢慢退出Web框架的历史舞台,但它的遗产仍然存在,存在的形式主要是需要测试和维护的应用程序。这个月,AndrewGlover向您介绍如何使用JUnit的...
1. 美国Segue公司的Silk系列产品 2. MaxQ 3. Httpunit 4. Junit 5. Jtest 6. Hansel 7. Cactus 8. JFCUnit 9. StrutsTestCase 10. TestNG
第1章 Java EE的基本知识 1 1.1 Java EE的出现及其特点 1 1.2 Java EE的分层模型和...23.4 利用StrutsTestCase对Struts进行测试 328 23.5 压力测试和JMeter 334 23.6 其他开源测试工具 339 23.7 小结 343
Yttrium 是一个用于“启动”安全 Web 应用程序开发的应用程序。 使用 Tomcat 5.5、MySQL 4 和 5、Maven、Ant、Spring、Hibernate、JUnit、Cactus、StrutsTestCase、JSTL、Struts 和许多其他框架。