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

我没有在这个领域看到任何我推荐给客户的东西.如果你使用过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());  
    ...        
    }
    ...
上一篇:arcgis for js 生成token


下一篇:JSR 168 and Portlet