单元测试servlet [英] Unit-testing servlets
问题描述
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屋!