是否有可用的符合标准 (168/286) 的 portlet 测试框架? (尤其是与 Spring PortletMVC 一起使用的)

发布于 2024-07-23 16:22:30 字数 393 浏览 3 评论 0原文

我在这个领域还没有看到任何我会推荐给客户的东西。 如果您使用过 Spring PortletMVC,您是如何测试它的?

在 portlet 代码级别下测试很容易,通过 HtmlUnit、Selenium 等在客户端测试相对容易,但我还没有看到任何本着 JSFUnit 精神的“灰盒”测试(在我看来这是前进的方向)。

  • Apache 的 Pluto 驱动程序理论上可用于引导测试工具。 有人试过这个吗?
  • 有存根或数据提供者方法吗?
  • 有什么方法可以解决两阶段处理问题?

I've not seen anything in this area I would recommend to a client. If you've used Spring PortletMVC, how did you test it?

It's easy to test under the level of portlet code, and relatively easy to test on the client side through HtmlUnit, Selenium and the like, but I haven't seen anything that is a "Gray Box" test in the spirit of JSFUnit (which looks to me to be the way forward).

  • Apache's Pluto driver could theoretically be used to bootstrap a test harness. Has anyone tried this?
  • Any stub or data provider approaches?
  • Any approach to address two-phase processing concerns?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

〗斷ホ乔殘χμё〖 2024-07-30 16:22:31

我对 portlet 一无所知,但就这样吧。

portletUnit

portletUnit是一个测试框架
用于在外部测试 JSR-168 portlet
portlet 容器就像 servletUnit
用于测试外部的 servlet
servlet 容器。 预计是
旨在映射功能
servletUnit 到 portlet 上
servletUnit 本身提供
portletUnit 的基础。

一些更多相关信息可以在他的 Project PortletUnit 博客 上找到,包括 PortletUnit 和 Spring Portlet:检查表单验证错误

当使用 portletUnit 进行测试时,它是
不明显如何检查是否存在
任何形式错误。 幸运的是,使用
的渲染侦听器功能
PortletRunner,有一个简单的方法
检查验证器错误。

还有 Nils-Helge Garli Hegvik 在 2007 年撰写的一篇博客文章,标题为 使用 Jetty、Pluto 和 JWebUnit 测试 Portlet

记得一篇精彩的文章
约翰内斯·布罗德沃尔的博客关于
与 Jetty 的集成测试和
JWebUnit,我想扩展他的
使用嵌入式的方法
我创建的 jetty-pluto 设置。 这
事实证明这很容易。

最后,Spring框架文档10.2单元测试< /a>.


org.springframework.mock.web.portlet
软件包包含一组Portlet API
模拟对象,针对使用
Spring 的 Portlet MVC 框架。

[...]org.springframework.test.web
包包含ModelAndViewAssert
可以与以下组合使用
任何测试框架(例如,JUnit 4+,
TestNG 等)用于处理单元测试
使用 Spring MVC ModelAndView 对象。

[...] 要测试您的 Spring MVC 控制器,请使用
ModelAndViewAssert 结合
MockHttpServletRequest,
MockHttpSession 等来自
org.springframework.mock.web包

这是 John Ferguson Smart 撰写的一篇相关文章,标题为
对 Spring-MVC 应用程序进行单元测试

这其中最棒的事情之一
框架的可测试性在于它的可测试性。 在
Spring-MVC,任何自定义验证器(用于
字段和表单验证)和
属性编辑器(用于转换文本
特定 Java 类型的字段)是
非常容易测试 - 你只需测试即可
它们就像是孤立的 POJO。

Spring-MVC还自带全套
您可以使用的模拟对象(与
一些练习)来测试你的
随心所欲的控制器。
例如,您可以使用类似的类
MockHttpServletRequest
MockHttpServletResponse 来模拟
您的 HTTP 请求和响应
对象。 这也变得更容易
事实上 Controller 可以是
实例化为普通 Java 类。
例如,假设您正在测试
页面的控制器类
更新客户详细信息记录。 你
可以非常简单地做到这一点,如下所示:

public class UpdateClientTest {
        //
        // Prepare your request
        //
        request.setMethod("POST");      
        request.setParameter("id", "100");
        request.setParameter("firstName", "Jane");
        request.setParameter("lastName", "Doe");
        //
        // Invoke the controller
        //
    controller = new ChoosePeriodController();
        ModelAndView mav = controller.handleRequest(request, response);
    //
    // Inject any service objects you need
    //
        controller.setClientService(clientService);
    ...
        //
        // Inspect the results
        //
        assert mav != null;
        assertEquals("displayClient",mav.getViewName());  
        Client client = (Client) mav.getModel().get("client");
        assertEquals("Jane",client.getFirstName());  
        assertEquals("Doe",client.getLastName());  
    ...        
    }
    ...

I don't know anything about portlets but here it goes.

There's portletUnit.

portletUnit is a testing framework
used to test JSR-168 portlets outside
portlet container just as servletUnit
is used to test servlets outside a
servlet container. The projected is
architected to map the functionally of
servletUnit onto portlets with
servletUnit itself providing the
foundation for portletUnit.

Some more related info could be found on his Project PortletUnit blog, including PortletUnit and Spring Portlet: Checking form validation errors.

When testing with portletUnit, it is
not obvious how to check if there were
any form errors. Fortunately, using
the render listener feature of
PortletRunner, there is a simple way
to check for validator errors.

There's also a blog article written by Nils-Helge Garli Hegvik in 2007 titled Testing Portlets with Jetty, Pluto and JWebUnit.

Remembering an excellent article from
Johannes Brodwall's blog about
integration testing with Jetty and
JWebUnit, I wanted to extend his
approach to use the embedded
jetty-pluto setup I have created. This
turned out to be to be quite easy.

Finally, Spring Framework documentation 10.2 Unit testing.

The
org.springframework.mock.web.portlet
package contains a set of Portlet API
mock objects, targeted at usage with
Spring's Portlet MVC framework.

[...] The org.springframework.test.web
package contains ModelAndViewAssert,
which can be used in combination with
any testing framework (e.g., JUnit 4+,
TestNG, etc.) for unit tests dealing
with Spring MVC ModelAndView objects.

[...] To test your Spring MVC Controllers, use
ModelAndViewAssert combined with
MockHttpServletRequest,
MockHttpSession, etc. from the
org.springframework.mock.web package.

Here's a related article written by John Ferguson Smart titled
Unit testing your Spring-MVC applications.

One of the great things about this
framework is how testable it is. In
Spring-MVC, any custom validators (for
field and form validation) and
property editors (for converting text
fields to specific Java types) are
dead-easy to test - you can just test
them as if they where isolated POJOs.

Spring-MVC also comes with a full set
of mock objects that you can use (with
a bit of practice) to test your
controllers to your heart's content.
For example, you can use classes like
MockHttpServletRequest and
MockHttpServletResponse to simulate
your HTTP request and response
objects. This is also made easier by
the fact that Controllers can be
instanciated as normal Java classes.
For example, imagine you are testing a
controller class for a page that
updates a client details record. You
could do this very simply as follows:

public class UpdateClientTest {
        //
        // Prepare your request
        //
        request.setMethod("POST");      
        request.setParameter("id", "100");
        request.setParameter("firstName", "Jane");
        request.setParameter("lastName", "Doe");
        //
        // Invoke the controller
        //
    controller = new ChoosePeriodController();
        ModelAndView mav = controller.handleRequest(request, response);
    //
    // Inject any service objects you need
    //
        controller.setClientService(clientService);
    ...
        //
        // Inspect the results
        //
        assert mav != null;
        assertEquals("displayClient",mav.getViewName());  
        Client client = (Client) mav.getModel().get("client");
        assertEquals("Jane",client.getFirstName());  
        assertEquals("Doe",client.getLastName());  
    ...        
    }
    ...
苹果你个爱泡泡 2024-07-30 16:22:31

检查 spring-test-portlet-mvc (https://github.com/markusf/spring- test-portlet-mvc),它将 MockMvc 的功能公开给 Portal 上下文,并让您轻松地集成测试 Spring Portlet。

Checkout spring-test-portlet-mvc (https://github.com/markusf/spring-test-portlet-mvc), which exposes the features of MockMvc to the Portal context and lets you integration test your Spring Portlets easily.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文