• 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

test case for servlets

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How to create test cases for servlets? Should I use JUNIT or I have to use CACTUS test suite??
Please give an example
 
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you elaborate a little bit on what the servlet does or are you just asking in general?

Depending on what the servlet renders, how complex of a servlet you want to test or how complex you want the tests to be will drive what is best for you.

Stand alone JUnit may not be the best as you'd have to deal with opening the port, reading responses, etc yourself. I'd suggest you look at HtmlUnit if you are working with some simple servlets. If you are doing something a little more complex then take a look at Selenium.

Note that I am assuming you are referring to a servlet rendering HTML.
 
Swastik Pal
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually I'm using a servlet to transfer control from a HTML page to another servlet. How to generate test cases for this controller servlet? Will JUnit be helpful in this case?
 
Brian Burress
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sounds like you should look at something like HtmlUnit or Selenium. I believe HtmlUnit is an extention of JUnit, while depending on which portion of Selenium you use it is more of less a JUnit extention as well (thinking the older RC or Remote Control) or can be using within JUnit (the newer Selenium Webdriver support).

I have used all three. Realize that none of these options, Junit included, is going to "test" your application for you. They are all just frameworks underwhich you need to understand what to test and then write the code to do it. (Not trying to talk down to you, just trying to clarify what you expect JUnit or Cactus to do for you.)

I suggest you start with HtmlUnit and write up a test to see if it can do what you want. In my opinion it is pretty simple to use, but I used it after I understood JUnit concepts.

If you use Selenium, the Webdriver option seems better overall but is relatively new so you may find you need to spend a little more time understanding it and even writing some of your own support classes.

Selenium RC is deprecated but may offer you a little more support information -- I recommend you avoid this one as it is deprecated and as such you should not expect enhancements from it. I have refactored a number of tests to use WebDriver that were RC and I think WebDriver is a much more solid, less error prone approach. The refactoring of the framework of the tests themselves was very simple, creating helpers to do what RC did out of the box is what slowed me down.

There are examples of all three on the web. Selenium as some good "hello world" examples in its documentaion. Google "junit test servlet", Selenium, etc and you should be on track to finding examples with which to start working.
 
This will take every ounce of my mental strength! All for a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic