One strategy is to factor out into helper classes any code that doesn't
directly depend on the JSP/Servlet API.  Those helpers can then be
easily tested in JUnit or whatever your favorite unit testing framework
is.  The tag handlers themselves are very thin wrappers that don't
contain any real logic.  This isn't as good as testing the full assembly
in a servlet container, but it can be much faster, so you can run the
helper tests frequently, and test the full tag less frequently.

And as an added bonus, you have more reusable code.  If you ever decide
to move away from JSP for some reason, you can use your tag helpers with
whatever new technology you adopt.

Struts itself uses this technique to an extent; a lot of the code in the
org.apache.struts.util.* classes exists primarily to be used by tag
classes.

-- 
Tim Moore / Blackboard Inc. / Software Engineer
1899 L Street, NW / 5th Floor / Washington, DC 20036
Phone 202-463-4860 ext. 258 / Fax 202-463-4863


> -----Original Message-----
> From: Davor Cengija [mailto:[EMAIL PROTECTED]] 
> Sent: Wednesday, September 25, 2002 3:34 AM
> To: Struts Developers List
> Subject: Unit testing taglibs?
> 
> 
> How to unit-test taglibs, possibly without servlet container?
> 
> I'm writing wml-related taglib for struts and my code is 
> craving for some unit-tests. I found tagunit but it requires 
> servlet container, it's executed in a jsp page etc. I'd like 
> to have automated unit testing on each build.
> 
> How does Cactus fit in? I recently discovered it but haven't 
> downloaded it yet.
> 
> Any sample tests?

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to