> hujd_cn wrote:
> > it is quite straight to test java classes with JUnit by writing
> > input data to methods and asserting output. but how can i generate
> > input data to JSP and then check validation of output from web server?
>
> Well, most importantly, make the JSPs contains as few logic as possible. Put
> as much of the logic as possible into POJOs and/or taglibs, and test those
> the usual way.
>
> If you really need to test the JSPs, you can use jWebUnit with ServletUnit
> as the test container (the latter comes with httpUnit), or Jetty as an
> embedded webserver.
When I tried faking the web container, I found that the JSP processor
pulls in such crazy stuff -- like Ant! -- that the complexity of the
test environment was no longer worth the effort. For that reason, I
cannot emphasize enough the need to push as much of the JSP out into
plain Java (POJOs or taglibs, as you say). The best you can do is test
the JSPs independently of the application that uses them, so write a
test servlet that allows you to stick arbitrary data into the Request,
then forwards to the JSP. This way you can test various error conditions
by simulating, not recreating them. It's not as nice as (say) Velocity,
but it'll do.
--
J. B. (Joe) Rainsberger
Diaspar Software Services
http://www.diasparsoftware.com
Author, JUnit Recipes: Practical Methods for Programmer Testing
| Yahoo! Groups Sponsor | |
|
|
Yahoo! Groups Links
- To visit your group on the web, go to:
http://groups.yahoo.com/group/junit/
- To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
- Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.
