在嵌入模式下对JSP进行单元测试 [英] Unit testing JSPs in embedded mode
问题描述
我正在构建一个对JSP进行单元测试的小框架。这些JSP有一些自定义标签,否则它们没有任何特殊之处。
I am in process of building up a small framework that does unit testing for JSPs. These JSPs have some custom tags, otherwise they are not any special.
虽然有许多Java单元测试解决方案可用,但我不想使用单独的完整方法启动-blown JSP容器,部署应用程序并通过TCP连接收集结果。这种情况的典型例子是Apache Cactus,Selenium等。理想情况下,我想要的是拥有尽可能轻量级的嵌入式解决方案(不需要网络连接是一个好兆头)。我还查看了各种模拟框架,但在单元测试期间编译/执行JSP时,发现没有一个简洁的工作示例。
Although there are numerous Java unit testing solutions available, I prefer not to use the method where a separate full-blown JSP container is launched, application deployed and results gathered via TCP connection. Typical examples of this case would be Apache Cactus, Selenium, etc. Ideally what I want is to have an embedded solution which is as lightweight as possible (network connection is not being required is a good sign). I have also looked at various mock frameworks but found not a single clean working example when a JSP is compiled/executed during the unit test.
我能够使用的最接近的解决方案find在嵌入模式下使用Jetty,或者特别是它的ServletTester类,如 http:// docs.codehaus.org/display/JETTY/ServletTester
The closest solution I was able to find was using Jetty in embedded mode, or in particular it's ServletTester class, as documented in http://docs.codehaus.org/display/JETTY/ServletTester
不幸的是,上述方法仅适用于servlet,但没有提及JSP。我认为有一种方法可以以编程方式将Jasper servlet挂钩,但却无法花费一周时间潜入Jetty / Jasper内部,只是为了获得两个集成。我不介意使用任何其他JSP / Servlet容器,只要它是免费且灵活可配置的。
Unfortunately the above method only works for servlets but has no mention of JSP. I presume there's a way to programatically hook Jasper servlet into it but can't afford spending a week diving into Jetty/Jasper internals just to get the two integrated. I don't mind using any other JSP/Servlet container as long as it is free and flexibly configurable.
如果有人有类似的设置并愿意分享,我将不胜感激经验。
I would appreciate if anyone's got a similar setup and willing to share the experience.
推荐答案
这是一个用jsps运行Jettys ServletTester的示例项目。
Here is a example project that run Jettys ServletTester with jsps.
https://github.com/genthaler/jetty-jsp-unit- test-simple /
这篇关于在嵌入模式下对JSP进行单元测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!