You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tiles.apache.org by Antonio Petrelli <an...@gmail.com> on 2009/09/01 09:22:27 UTC

Re: Classes extending junit testcase

2009/8/30 Roshni Basu <ro...@gmail.com>:
>
> I was going through the
> http://tiles.apache.org/2.1/framework/testapidocs/org/apache/tiles/factory/package-summary.html.
> Will these testapis help me in testing layout?

Absolutely no! These are unit test classes.
What do you mean with "testing layout"?

Antonio

Re: Classes extending junit testcase

Posted by Antonio Petrelli <an...@gmail.com>.
2009/9/1 Roshni Basu <ro...@gmail.com>:
> I tried the same approach of testing a class which extends PutAttribute
> class. But this is not working.
> Whether tiles tag renders html code?

Tiles tags to not render HTML code directly. They, instead, load,
prepare and display code coming from other sources (JSPs, string
attributes, etc.).
I must admit that in Tiles <= 2.1.x there is no a serious unit testing
for JSP tags, but with Tiles 2.2.x there are *real* unit tests, using
EasyMock to mock the requests and the responses, in the
"tiles-template" module, that is a base "template tags" module for
JSP, FreeMarker and Velocity and contains all of the common code.

Antonio

Re: Classes extending junit testcase

Posted by Roshni Basu <ro...@gmail.com>.
Yes, using selenium I can test the functionality.
Actually I was using Spring Testing framework to write unit testcases for my
custom tags which actually renders html code.
for example i have a tag soemthing like this:

public class TextFieldTag extends TagSupport{

    private String name;
    private HttpServletResponse response;

    // A setter for an attribute that will be set in the custom tag
    public void setName(String name) {
        this.name = name;
    }
    public String getName() {
        return  this.name;
    }
    protected int doStartTagInternal() throws Exception {
            JspWriter out = pageContext.getOut();
            try {
                out.print("<html>");
                out.print("<input type=\"text\" name="+getName()+"
disabled=\"true\"/>");
                out.print("</html>");
            } catch (Exception e) {
                e.printStackTrace();
            }
            return SKIP_BODY;
        }


    }
For this i can write a test case to test doStartTagInternal() something like
this:

public void testDoStartTag() throws Exception{
         String expectedOutput = "<html><input type=\"text\" name=test1
disabled=\"true\"/></html>";
         someCustomTag=new TextFieldTag();
         someCustomTag.setName("test1");
         someCustomTag.setPageContext(mockPageContext);

         int tagReturnValue = someCustomTag.doStartTagInternal();
         String output = ((MockHttpServletResponse)
mockPageContext.getResponse()).getContentAsString();

         assertEquals("Tag should return 'SKIP_BODY'", TagSupport.SKIP_BODY,
tagReturnValue);
         assertEquals(expectedOutput, output);

     }


I tried the same approach of testing a class which extends PutAttribute
class. But this is not working.
Whether tiles tag renders html code?

On Tue, Sep 1, 2009 at 2:25 PM, Antonio Petrelli <antonio.petrelli@gmail.com
> wrote:

> 2009/9/1 Roshni Basu <ro...@gmail.com>:
> > I'm confused how to write unit testcases for class extending tiles tag.
> > Is only JUnit sufficient ?
>
> Probably yes, but you might want to take a look at Selenium:
> http://seleniumhq.org/
>
> The Tiles test webapp uses it:
> http://svn.eu.apache.org/repos/asf/tiles/framework/trunk/tiles-test/
>
> See:
> http://tiles.apache.org/framework/selenium.html
>
> Antonio
>

Re: Classes extending junit testcase

Posted by Antonio Petrelli <an...@gmail.com>.
2009/9/1 Roshni Basu <ro...@gmail.com>:
> I'm confused how to write unit testcases for class extending tiles tag.
> Is only JUnit sufficient ?

Probably yes, but you might want to take a look at Selenium:
http://seleniumhq.org/

The Tiles test webapp uses it:
http://svn.eu.apache.org/repos/asf/tiles/framework/trunk/tiles-test/

See:
http://tiles.apache.org/framework/selenium.html

Antonio

Re: Classes extending junit testcase

Posted by Roshni Basu <ro...@gmail.com>.
Thanks.

I'm confused how to write unit testcases for class extending tiles tag.
Is only JUnit sufficient ?


On Tue, Sep 1, 2009 at 1:11 PM, Antonio Petrelli <antonio.petrelli@gmail.com
> wrote:

> 2009/9/1 Roshni Basu <ro...@gmail.com>:
> > Actually I want to write unit testcases for classes extending Tiles
> classes.
> > So will these apis help me ?
>
> The not "*Test" classes might help (they are almost stub classes), but
> most of them are specific to the tested class. The pattern is:
> NameOfTheClass
> NameOfTheClassTest
> or
> TestNameOfTheClass
>
> In fact, with JUnit 4.x you don't need to extend TestCase at all, by
> using annotations.
> I suggest you to take a look at the JUnit website.
>
> Ciao
> Antonio
>

Re: Classes extending junit testcase

Posted by Antonio Petrelli <an...@gmail.com>.
2009/9/1 Roshni Basu <ro...@gmail.com>:
> Actually I want to write unit testcases for classes extending Tiles classes.
> So will these apis help me ?

The not "*Test" classes might help (they are almost stub classes), but
most of them are specific to the tested class. The pattern is:
NameOfTheClass
NameOfTheClassTest
or
TestNameOfTheClass

In fact, with JUnit 4.x you don't need to extend TestCase at all, by
using annotations.
I suggest you to take a look at the JUnit website.

Ciao
Antonio

Re: Classes extending junit testcase

Posted by Roshni Basu <ro...@gmail.com>.
Actually I want to write unit testcases for classes extending Tiles classes.
So will these apis help me ?

On Tue, Sep 1, 2009 at 12:52 PM, Antonio Petrelli <
antonio.petrelli@gmail.com> wrote:

> 2009/8/30 Roshni Basu <ro...@gmail.com>:
> >
> > I was going through the
> >
> http://tiles.apache.org/2.1/framework/testapidocs/org/apache/tiles/factory/package-summary.html
> .
> > Will these testapis help me in testing layout?
>
> Absolutely no! These are unit test classes.
> What do you mean with "testing layout"?
>
> Antonio
>