You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by Kent Tong <ke...@cpttm.org.mo> on 2006/12/15 16:59:15 UTC

T5: page level integration tests

Hi,

Making it easier to test an component or a page in Tapestry in a
in-process manner (out of container) has been my biggest itch. 
Testing with Selenium is fine for AJAX stuff, but for plain HTML 
stuff, it is too slow. In addition, it is also hard to debug into 
the code as it is run in a separate process.

To make in-process testing possible, I've written some code and it 
seems to work fine. A TestNG case for the If component is shown below.
The only significant change to the framework is that I'll need
the capacity to override service implementations with mock objects
(eg, to replace those accessing HttpServletRequest). The overrides
are treated pretty much like the built-in services. The changed
code is localized to RegistryImpl. If you have better ideas, please
let me know. Otherwise, I'll commit the code for you to have a 
look. Note that for the moment the test harness only supports 
rendering of very simple pages (no session, no query parameters,
no context).

public class IfTest extends Assert
{
    private PageTester tester;

    @Test
    public void testRender()
    {
        String appPackage = "org.apache.tapestry.integration.pagelevel.app2";
        String appName = "";
        tester = new PageTester(appPackage, appName);
        Document doc = tester.renderPage("TestPageForIf");
        assertNotNull(doc.getElementById("1"));
        assertNotNull(doc.getElementById("3"));
        assertNull(doc.getElementById("2"));
        assertNull(doc.getElementById("4"));
    }
}

TestPageForIf.html is:

<html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">
<t:comp type="If" test="true">
	<p id="1">abc.</p>
</t:comp>
<t:comp type="If" test="false">
	<p id="2">def.</p>
</t:comp>
<t:comp type="If" test="property1">
	<p id="3">111.</p>
</t:comp>
<t:comp type="If" test="property2">
	<p id="4">222.</p>
</t:comp>
</html>

TestPageForIf.java is:

@ComponentClass
public class TestPageForIf
{
    private boolean property1 = true;

    private boolean property2 = false;

    public boolean isProperty1()
    {
        return property1;
    }

    public boolean isProperty2()
    {
        return property2;
    }

}

--
Author of a book for learning Tapestry (http://www.agileskills2.org/EWDT)


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tapestry.apache.org
For additional commands, e-mail: dev-help@tapestry.apache.org


Re: T5: page level integration tests

Posted by Howard Lewis Ship <hl...@gmail.com>.
Having the ability to perform a unit test of a component or page, without
cranking up Selenium, is a good idea. I don't know that it will be as
definitive as using Selenium, however.

On 12/15/06, Kent Tong <ke...@cpttm.org.mo> wrote:
>
> Hi,
>
> Making it easier to test an component or a page in Tapestry in a
> in-process manner (out of container) has been my biggest itch.
> Testing with Selenium is fine for AJAX stuff, but for plain HTML
> stuff, it is too slow. In addition, it is also hard to debug into
> the code as it is run in a separate process.
>
> To make in-process testing possible, I've written some code and it
> seems to work fine. A TestNG case for the If component is shown below.
> The only significant change to the framework is that I'll need
> the capacity to override service implementations with mock objects
> (eg, to replace those accessing HttpServletRequest). The overrides
> are treated pretty much like the built-in services. The changed
> code is localized to RegistryImpl. If you have better ideas, please
> let me know. Otherwise, I'll commit the code for you to have a
> look. Note that for the moment the test harness only supports
> rendering of very simple pages (no session, no query parameters,
> no context).
>
> public class IfTest extends Assert
> {
>     private PageTester tester;
>
>     @Test
>     public void testRender()
>     {
>         String appPackage = "
> org.apache.tapestry.integration.pagelevel.app2";
>         String appName = "";
>         tester = new PageTester(appPackage, appName);
>         Document doc = tester.renderPage("TestPageForIf");
>         assertNotNull(doc.getElementById("1"));
>         assertNotNull(doc.getElementById("3"));
>         assertNull(doc.getElementById("2"));
>         assertNull(doc.getElementById("4"));
>     }
> }
>
> TestPageForIf.html is:
>
> <html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">
> <t:comp type="If" test="true">
>         <p id="1">abc.</p>
> </t:comp>
> <t:comp type="If" test="false">
>         <p id="2">def.</p>
> </t:comp>
> <t:comp type="If" test="property1">
>         <p id="3">111.</p>
> </t:comp>
> <t:comp type="If" test="property2">
>         <p id="4">222.</p>
> </t:comp>
> </html>
>
> TestPageForIf.java is:
>
> @ComponentClass
> public class TestPageForIf
> {
>     private boolean property1 = true;
>
>     private boolean property2 = false;
>
>     public boolean isProperty1()
>     {
>         return property1;
>     }
>
>     public boolean isProperty2()
>     {
>         return property2;
>     }
>
> }
>
> --
> Author of a book for learning Tapestry (http://www.agileskills2.org/EWDT)
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: dev-help@tapestry.apache.org
>
>


-- 
Howard M. Lewis Ship
TWD Consulting, Inc.
Independent J2EE / Open-Source Java Consultant
Creator and PMC Chair, Apache Tapestry
Creator, Apache HiveMind

Professional Tapestry training, mentoring, support
and project work.  http://howardlewisship.com

Re: T5: page level integration tests

Posted by Kent Tong <ke...@cpttm.org.mo>.
Howard Lewis Ship <hlship <at> gmail.com> writes:

> The other question is whether changing RegistryImpl is necessary.  Using
> infrastructure overrrides may be sufficient.

I thought about this too. In order to easily unit test a page which makes 
use a service layer using the Tapestry IOC, we need to a way to replace 
the service with a mock object. So the Infrastructure override mechanism
won't do it.

--
Author of a book for learning Tapestry (http://www.agileskills2.org/EWDT)




---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tapestry.apache.org
For additional commands, e-mail: dev-help@tapestry.apache.org


Re: T5: page level integration tests

Posted by Howard Lewis Ship <hl...@gmail.com>.
The other question is whether changing RegistryImpl is necessary.  Using
infrastructure overrrides may be sufficient.

On 12/15/06, Kent Tong <ke...@cpttm.org.mo> wrote:
>
> Hi,
>
> Making it easier to test an component or a page in Tapestry in a
> in-process manner (out of container) has been my biggest itch.
> Testing with Selenium is fine for AJAX stuff, but for plain HTML
> stuff, it is too slow. In addition, it is also hard to debug into
> the code as it is run in a separate process.
>
> To make in-process testing possible, I've written some code and it
> seems to work fine. A TestNG case for the If component is shown below.
> The only significant change to the framework is that I'll need
> the capacity to override service implementations with mock objects
> (eg, to replace those accessing HttpServletRequest). The overrides
> are treated pretty much like the built-in services. The changed
> code is localized to RegistryImpl. If you have better ideas, please
> let me know. Otherwise, I'll commit the code for you to have a
> look. Note that for the moment the test harness only supports
> rendering of very simple pages (no session, no query parameters,
> no context).
>
> public class IfTest extends Assert
> {
>     private PageTester tester;
>
>     @Test
>     public void testRender()
>     {
>         String appPackage = "
> org.apache.tapestry.integration.pagelevel.app2";
>         String appName = "";
>         tester = new PageTester(appPackage, appName);
>         Document doc = tester.renderPage("TestPageForIf");
>         assertNotNull(doc.getElementById("1"));
>         assertNotNull(doc.getElementById("3"));
>         assertNull(doc.getElementById("2"));
>         assertNull(doc.getElementById("4"));
>     }
> }
>
> TestPageForIf.html is:
>
> <html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">
> <t:comp type="If" test="true">
>         <p id="1">abc.</p>
> </t:comp>
> <t:comp type="If" test="false">
>         <p id="2">def.</p>
> </t:comp>
> <t:comp type="If" test="property1">
>         <p id="3">111.</p>
> </t:comp>
> <t:comp type="If" test="property2">
>         <p id="4">222.</p>
> </t:comp>
> </html>
>
> TestPageForIf.java is:
>
> @ComponentClass
> public class TestPageForIf
> {
>     private boolean property1 = true;
>
>     private boolean property2 = false;
>
>     public boolean isProperty1()
>     {
>         return property1;
>     }
>
>     public boolean isProperty2()
>     {
>         return property2;
>     }
>
> }
>
> --
> Author of a book for learning Tapestry (http://www.agileskills2.org/EWDT)
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: dev-help@tapestry.apache.org
>
>


-- 
Howard M. Lewis Ship
TWD Consulting, Inc.
Independent J2EE / Open-Source Java Consultant
Creator and PMC Chair, Apache Tapestry
Creator, Apache HiveMind

Professional Tapestry training, mentoring, support
and project work.  http://howardlewisship.com