单元测试servlet

编程入门 行业动态 更新时间:2024-10-22 11:31:00
本文介绍了单元测试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

本文发布于:2023-11-14 19:26:53,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1588329.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:单元测试   servlet

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!