单元测试 servlet [英] Unit-testing servlets

查看:32
本文介绍了单元测试 servlet的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一堆 servlet 在 Tomcat servlet 容器下运行.我想将测试代码与生产代码分开,所以我考虑使用测试框架.JUnit 很好地集成到 Eclipse 中,但我未能使用正在运行的 Tomcat 服务器使其运行 servlet.你能推荐一个支持测试Tomcat servlet的单元测试框架吗?Eclipse 集成很好,但不是必需的.

I have a bunch of servlets running under the Tomcat servlet container. I would like to separate test code from production code, so I considered using a test framework. JUnit is nicely integrated into Eclipse, but I failed to make it run servlets using a running Tomcat server. Could you please recommend a unit testing framework that supports testing Tomcat servlets? Eclipse integration is nice but not necessary.

推荐答案

查看 ServletUnit,它是 HttpUnit 的一部分.简而言之,ServletUnit 提供了一个模拟和实用程序库,您可以在普通 JUnit 测试中使用它来模拟 servlet 容器和其他与 servlet 相关的对象,如请求和响应对象.上面的链接包含示例.

Check out ServletUnit, which is part of HttpUnit. In a nutshell, ServletUnit provides a library of mocks and utilities you can use in ordinary JUnit tests to mock out a servlet container and other servlet-related objects like request and response objects. The link above contains examples.

这篇关于单元测试 servlet的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆