- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我计划通过 ServletUnit 对我的 Servlet 进行单元测试,但遇到了一些问题:
- 作为起点,我们应该创建一个 ServletRunner 对象。构造函数之一需要带有 web.xml 文件的 File 对象。我提供了 web.xml 文件的完整路径,但不知何故它忽略了提供的路径并在顶级文件夹中进行搜索。代码片段和错误消息如下:
代码片段
ServletRunner sr = new ServletRunner(new File("* C:/eclipse-workspaces/pocs/lms-csd/src/main/webapp/WEB-INF/web.xml*"));
ServletUnitClient sc = sr.newClient();
WebRequest request = new PostMethodWebRequest("path to be specified" ); request.setParameter( "userId", "test" );
request.setParameter( "password", "csd" );
WebResponse response = sc.getResponse(request);
String text = response.getText();
Assert.assertTrue(text.contains("欢迎使用休假管理系统"));
堆栈跟踪
com.meterware.httpunit.HttpInternalErrorException:
Error on HTTP request: 500 org.apache.jasper.JasperException: java.io.FileNotFoundException: * C:\eclipse-workspaces\pocs\lms-csd\WEB-INF\web.xml*
(The system cannot find the path specified)
[http://localhost/login] - 为什么系统不断查看文件夹结构为.../WEB-INF/web.xml。 我的项目是一个 Maven 项目,我不想改变项目的结构来适应这种方式。如何使 ServletRunner 类从指定文件夹中读取? - 在Servlet代码中,我使用以下代码:
String result = null if (someCondition) result = "/welcome.jsp"; } else { logger.warn("Password Validation failed"); request.setAttribute("failedlogin", new Boolean(true)); result = "/index.jsp"; } } RequestDispatcher requestDispatcher = getServletContext().getRequestDispatcher(result); requestDispatcher.forward(request, response);
ServletUnit 再次期望welcome.jsp 位于根文件夹中,尽管jsp 文件存在于.../src/main/webapp/文件夹中。同样,如何告知 ServletUnit 目标文件夹位置?
提前非常感谢。
致以诚挚的问候M.SuriNaidu
最佳答案
这就是我所做的事情。这是我的 servlet 测试的基类的传真。在本例中,我传递 web.xml 文件的相对路径,因为它存在于我的源代码树中。我从 ant 和 eclipse 运行这些测试。
abstract public class ServletTestCase {
protected ServletRunner m_runner;
protected ServletUnitClient m_client;
protected String m_userAgent = "something/1.0";
@Override
protected void setUp() throws Exception {
super.setUp();
initHttpUnit();
}
@Override
protected void tearDown() throws Exception {
shutdownHttpUnit();
super.tearDown();
}
protected void initHttpUnit() throws IOException, SAXException {
shutdownHttpUnit();
// We are expecting UTF-8 character handling in URLs, make it the default
HttpUnitOptions.setDefaultCharacterSet("UTF-8");
// Find the servlet's web.xml file and use it to init servletunit
File file = new File("tests/web.xml"));
m_runner = new ServletRunner(file);
m_client = m_runner.newClient();
m_client.getClientProperties().setUserAgent(m_userAgent);
}
protected void shutdownHttpUnit() {
if (m_runner != null) {
m_runner.shutDown();
}
m_client = null;
m_runner = null;
}
}
关于java - 如何使用 HttpUnit servlet runner 运行 servlet 测试? ServletUnit 启动时遇到问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15018809/
我会公开承认我站在测试驱动开发的一边。我遇到了一个我想测试的情况,但我还没有找到这样做的好方法。 我一直在 ASP.NET MVC 中工作,我想测试我放入 View 层的代码部分(我知道我需要保持尽可
我正在尝试学习 HTTPUnit 并已阅读 http://httpunit.sourceforge.net/doc/cookbook.html 上提到的食谱 但是当我尝试这个非常简单的代码时 pack
我已经开始学习 HTTPUNIT 并找到了一个基本示例。 在此示例中,它将访问此 site 。它将搜索包含 HTTPUNIT 的链接。它会打印 HTTPUNIT 上的链接数。 。我在我的机器上尝试了这
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 我们不允许提问寻求书籍、工具、软件库等的推荐。您可以编辑问题,以便用事实和引用来回答。 关闭 3 年前。
是否HttpUnit支持从带有 xml 参数的 HTTP POST 获取响应吗? 编辑 如果你想发送一个 post 请求,你可以实例化一个 PostMethodWebRequest 对象。 WebRe
我的任务是编写一组 http 单元测试,这些测试应该作为单线程应用程序在外部服务器上部署和启动。 经过一些调查和阅读文档后,我得出以下应用程序结构: public static void main(S
我正在使用 HttpUnit 来模拟此网站:http://www.voyages-sncf.com/这是我的代码:它不会向我发送最终的重定向 url,只是发送搜索的 url,而不是结果 public
如何从 WebConversation 或 WebRequest 对象的上下文中忽略 SSL 证书问题?我知道我可以创建一个接受所有证书的假 TrustManager 但我如何在 HttpUnit 上
目前我正在为 j2ee 应用程序开发单元测试。它使用 jQuery 1.4 版。 当我尝试单击链接并转到下一个网页时(在 java 测试代码中),HttpUnit 失败并出现异常: org.mozil
我确实遇到了奇怪的错误。这是我的 maven 部门: httpunit httpunit 1.7
一直在尝试找到一种在 HTTPUnit 中获取 HTMLElement 的字符串表示形式的方法。我在一些测试中使用 HTTPUnit 来获取响应 HTML,并且可以获取元素的文本内容,但这不包括其周围
3 年前,当我探索并研究 HttpUnit 时,我喜欢它的功能。尽管在三年没有跟踪它之后,当我向我的同事建议基于它的解决方案时,他告诉我它已被弃用? apache 状态表明它处于事件状态。我在哪里找不
我已经连续近 6 个小时试图找到解决方法,但没有成功。 我有一个简单的 HttpUnit 程序,可以登录网站。问题是当我最终提交登录表单时出现此错误: Exception in thread "mai
我正在使用 httpunit ServletRunner 进行 servlet 测试。现在我想测试使用请求属性(而不是参数)的 servlet。属性由我的过滤器放入请求中。因此,为了使 servlet
我们有一个 REST 服务,我们想对其进行测试。为此,我考虑过使用 HttpUnit。我们向资源 URL 发送 POST 请求,在收到请求后我们从请求中检索文件。在我们的服务器代码中,我们有这样的东西
我正在尝试在 HttpUnit 中编写一些测试用例来测试一个包含大量 Javascript 的网站。 HttpUnit 工作得很好 - 前提是我通过 HttpUnitOptions.setJavaSc
我的目标是能够使用 HttpUnit 爬行我的网页并查看后台正在触发和未触发的内容...我已经让它连接到我的页面,并且如果我设置 HttpUnitOptions.setLoggingHttpHeade
我正在使用HttpUnit来模拟设计到指定url的表单的提交按钮单击。 (我正在使用 http://stu21.kntu.ac.ir/Login.aspx )。我使用如下代码来获取响应页面。 WebC
我正在寻找 android 上的浏览器模拟库,它可以处理类似的事情 加载网站 (http/https) 重定向:HTTP(3xx 状态代码)、JavaScript、HMTL 标记 填写 html
我正在尝试使用 HtmlUnit、HttpUnit 或任何类似的库在我的应用程序(在 Google App Engine 下运行)中加载网页的 DOM。 有没有人设法做类似的事情? 最佳答案 根据发行
我是一名优秀的程序员,十分优秀!