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

标签 unit-testing spring portal

我在这方面没有看到任何我会推荐给客户的东西。如果您使用过 Spring PortletMVC,您是如何对其进行测试的?

在portlet代码层面下测试比较容易,在客户端通过HtmlUnit、Selenium等比较容易测试,但是我还没有看到什么是JSFUnit精神的“灰盒”测试(在我看来是前进的道路)。

  • Apache 的 Pluto驱动程序理论上可用于引导测试工具。有没有人试过这个?
  • 任何 stub 或数据提供者方法?
  • 任何解决两阶段处理问题的方法?
  • 最佳答案

    我对 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 框架文档 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());  
        ...        
        }
        ...
    

    关于unit-testing - 是否有可用的符合标准 (168/286) 的 portlet 测试框架? (尤其是与 Spring PortletMVC 一起使用的那个),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/964907/

    相关文章:

    java - Lombok + QueryDsl + Mapstruct : error compiling: java. lang.NoClassDefFoundError : javax/persistence/Entity: javax. persistence.Entity

    java - 找不到依赖项 : Spring MVC 类型的匹配 bean

    spring - 如何将 Spring Hatoas ControllerLinkBuilder 用于 Thymeleaf 模板化的预定电子邮件

    java - 门户 Controller 的 setContentType 失败

    angular - 如何对依赖于元素高度的组件进行单元测试( Angular 为 5)?

    unit-testing - 在 TDD 中,测试是否应该由实现被测功能的人编写?

    iOS 配置门户 - 通配符应用程序 ID 以及显式应用程序 ID

    java - 为 Liferay 开发 portlet 的限制/缺点

    unit-testing - 乌鸦数据库 : Force indexes to wait until not stale whilst unit testing

    php - 在PHPUnit测试中有没有办法将 'expect'输出到error_log?