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 <[email protected]
> wrote:

> 2009/9/1 Roshni Basu <[email protected]>:
> > 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
>

Reply via email to