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

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

问题描述

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

解决方案

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


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.

解决方案

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天全站免登陆