单元测试Java Servlet [英] Unit testing a Java Servlet
问题描述
我想知道对servlet进行单元测试的最佳方法是什么。
I would like to know what would be the best way to do unit testing of a servlet.
测试内部方法不是问题,只要它们不引用servlet上下文,而是测试doGet / doPost方法以及内部方法引用上下文或使用会话参数?
Testing internal methods is not a problem as long as they don't refer to the servlet context, but what about testing the doGet/doPost methods as well as the internal method that refer to the context or make use of session parameters?
有没有办法简单地使用JUnit等经典工具,或者最好使用TestNG?我是否需要嵌入tomcat服务器或类似的东西?
Is there a way to do this simply using classical tools such as JUnit, or preferrably TestNG? Did I need to embed a tomcat server or something like that?
推荐答案
尝试 HttpUnit ,尽管您可能最终编写的自动化测试比单元测试(单个类)更集成测试(模块) 。
Try HttpUnit, although you are likely to end up writing automated tests that are more 'integration tests' (of a module) than 'unit tests' (of a single class).
这篇关于单元测试Java Servlet的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!