• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Unit testing custom tags out-of-container

 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to be able to unit test my JSP custom tags without running the tests in a container. My thinking is that, ultimately, all my tags just generate HTML, which is XML, so why couldn't I have a framework that minimally (mockobject-style where appropriate) fakes the container for the purpose of executing a single custom tag's interface methods, and then allowing me to assert on the parsed contents of the HTML that the tag generates? What would I be missing in this setup? I'm sure that there are cases of advanced inter-tag and tag/container collaboration that wouldn't be covered by this kind of structure, but I think I'd get really far with this. All my problems so far with my tags have been with them producing broken or semantically incorrect HTML.
Comments?
[ April 28, 2004: Message edited by: Allan Halme ]
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Allan,
I've tested tags using mock objects. It works out well because you can test the tag in isolation. I haven't experienced any big drawbacks.
The stated one is that you don't test interaction with the container. But for straighforward operations like getting data from the session, you know how the container is going to work.
 
sharp shooter, and author
Posts: 1913
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I agree, testing them out of container in your situation will get you quite far. If you do have the need to run them in-container, take a look at TagUnit. It's an in-container testing framework specifically for testing custom tags and in addition to just helping you test the tags, it looks at potential problems in the TLD file. For example, those times when you've forgotten to add a setter method for an attribute or missed the tag handler class from your webapp's classpath.
As with all testing, you'll probably need to use multiple tools to get a good coverage and overall confidence.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic