Win a copy of Spring Boot in Practice this week in the Spring forum!
  • 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
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

JUnit is for J2EE Web Applications also?

 
Ranch Hand
Posts: 395
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I have been involved in web application development using J2EE technologies. As it is in most development, my development activities doesn't use EJBs., its only Java Beans, JSP and Servlets.
I have heard a lot about JUnit testing framework which is widely used for Unit and regression testing of J2EE components.
Can I use JUnit for testing JSP and Servlets, which not necessarily have 100% server side business logic, I could even use some Java Script for validations and so on.
Does JUnit take care of Java Script also? Ot I need to go for Testing tools like Win Runner or Silk test or so on...??
Cheers.
 
Author
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by L Goundalkar:
Hi,
I have been involved in web application development using J2EE technologies. As it is in most development, my development activities doesn't use EJBs., its only Java Beans, JSP and Servlets.
I have heard a lot about JUnit testing framework which is widely used for Unit and regression testing of J2EE components.
Can I use JUnit for testing JSP and Servlets, which not necessarily have 100% server side business logic, I could even use some Java Script for validations and so on.
Does JUnit take care of Java Script also? Ot I need to go for Testing tools like Win Runner or Silk test or so on...??
Cheers.


JUnit will not really help you to unit test J2EE components. You need something more for that. You have 2 options:
- run the test outside the container. It means you won't have access to container-provided objects (such as HttpServletRequest, etc). So you'll need to provide those in your test. An excellent solution is to use the mock objects strategy to automatically provide those.
- run the test inside the container, using Cactus. Cactus will provide these container objects to your test.
Note: Cactus will let you unit test JSP pages and JSP tags. Testing JSPs is not possible with a pure JUnit solution.
Actually, thinking about it, I'm not sure to understand whether you're interested in unit testing or functional testing? I've answerer for the unit testing part above. If you're looking into "functional" testing, you can use a tool like HttpUnit. It can also test javascript (never tested it though).
Thanks
-Vincent
JUnit in Action author
 
L Goundalkar
Ranch Hand
Posts: 395
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Vincent,
As i mentioned above, my project has only Java Beans and Servelts which are on server side having business logic implemented in them and JSPs with Scripts and custom / standard tags for presentation and minor validations as business logic.
As you mentioned I can't use JUnit directly for my servlets.
In our framework, the data manipulation which is done in JSPs use the same server components by passing the information for these components about the database details to be acted upon.
So If I test my server side component once its through.
But the JSPs which we use will certainly be different for different modules and each would have some basic validations and some business logic ( for example enabling or disabling the buttons ).
For this scenario, can I use JUnit or i need to use HttpUnit? or is there any tool already available which takes care of extending JUnit for such scenarios?
Cheers.
 
reply
    Bookmark Topic Watch Topic
  • New Topic