• 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
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

I need a sample project regarding JSF UNIT testing

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please help me,
if any body knows about jsf unit testing, i am not understanding with the things said @ jboss.org.
 
Saloon Keeper
Posts: 28713
211
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Unit testing refers to testing components of an application as an individual unit. Typically in Java, this means creating a parallel class for each class which has testable features. So for example, "UserProfileBean" might have a JUnit test class named "UserProfileBeanTest". JUnit is one of the most common unit-testing frameworks, but there are others as well.

There's some excellent documentation, tutorials and samples on the JUnit website.

One of JSF's major advantages is its ability to be work with basic unit testing. The ideal JSF backing bean has little or no JSF-specific code in it, and therefore little need for the special environment of a web application. That allows you to run JUnit tests as stand-alone executions without the tedious overhead of starting and stopping an appserver.

Some of the most popular IDEs provide assistance in creating and running JUnit test classes.
 
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'll second what Tim says. When you are writing a class (often a bean in the case of JSF), you should be thinking "How can I unit test this?" If you are thinking that way, you will accomplish two things:
1) You'll be able to write and run unit tests!
2) Your code will often be less brittle and easier to change/upgrade in the future as you are forced to think about abstraction etc.

You don't have to test every single path through every single method (although that would be the ideal), but getting over 80% code coverage should give you confidence that things are working before you release into Testing.

If you use Apache Ant (or something similar), you could even set things up to take the latest code out of source control and run the unit tests every night. that way you get to find out about problems as early as possible.

Unit Testing might seem to be a pain, and it can take a long time to get going if you have already written a lot of code, but it will more than pay for itself in terms of a lower defect rate and application stability. It's often said that a bug found during development costs one tenth as much if the same bug being discovered in a deployed product. That's some saving!

(Another useful thing to do is Static Code Analysis, I think "FindBugs" is a great little tool for this; I've caught an awful lot of stupid mistakes with it! Not my code of course, cough, cough. Ahem.)
 
reply
    Bookmark Topic Watch Topic
  • New Topic