ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

单元测试 – 是否有可用的符合标准的(168/286)portlet测试框架? (特别是与Spring PortletMVC一起使用的)

2019-08-27 18:19:01  阅读:251  来源: 互联网

标签:portal unit-testing spring


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

在portlet代码级别下测试很容易,并且通过HtmlUnit,Selenium等在客户端测试相对容易,但我没有看到任何与JSFUnit精神相关的“灰盒子”测试(其中期待我前进的方向).

> Apache的Pluto驱动程序理论上可用于引导测试工具.有没人试过这个?
>任何存根或数据提供者接近?
>解决两阶段处理问题的方法有哪些?

解决方法:

我对portlet一无所知,但在这里.

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.

他的Project PortletUnit blog可以找到更多相关信息,包括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.

还有一篇由Nils-Helge Garli Hegvik于2007年撰写的博客文章,标题为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.

最后,Spring Framework文档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.

这是John Ferguson Smart撰写的一篇相关文章
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());  
    ...        
    }
    ...

标签:portal,unit-testing,spring
来源: https://codeday.me/bug/20190827/1743359.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有