Testing JSF application with JSFUnit

来源:互联网 发布:淘宝服务市场的代运营 编辑:程序博客网 时间:2024/04/27 08:27

People refer JSF as the implementation of this specification - 

a server-side, user-interface, component framework for Java technology based applications.

some implementations:

Apache MyFaces

Sun's Mojarra JFS Reference Implementation


JSFUnit is step on Cactus, means when writing, also need to extend like ServletTestCase, JSFUnit is heavily lie on HtmlUnit, so it can integrate with HtmlUnit to test fron-end.

Basically first create JSFSession, then using it to get JSFServerSession and JSFClientSession. serverSession use to verify Bean Java logic and clientSession can verify html along with HtmlUnit.


public void testCommandButton() throws IOException, SAXException{


        JSFSession jsfSession = new JSFSession("/album_details.jsp");


        JSFServerSession serverSession = jsfSession.getJSFServerSession();
        JSFClientSession clientSession = jsfSession.getJSFClientSession();

        clientSession.click("PurchaseButton");
        Object userBeanValue = serverSession.getManagedBeanValue("#{albumDetailsBean.status}");

        Assert.assertEquals("Successfully purchased:", userBeanValue);

        String spanContent = ((HtmlPage)clientSession.getContentPage()).getElementsByTagName("span").item(0).getTextContent();

        Assert.assertEquals("Successfully purchased:", spanContent);
    }


原创粉丝点击