File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes Unit Testability  ---JSF Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Unit Testability  ---JSF" Watch "Unit Testability  ---JSF" New topic
Author

Unit Testability ---JSF

Mcgill Smith
Ranch Hand

Joined: Nov 11, 2003
Posts: 178
In JSF can Components be tested independently as pure java objects?



Thanks


Regards
Mcgill
David Geary
Author
Ranch Hand

Joined: Apr 23, 2003
Posts: 45
You can test JSF components, but you'd have to mock a fair bit of the JSF implementation. The JSF Reference Implementation does that for internal testing.


David Geary Sabreware, Inc<br /><a href="http://www.corejsf.com" target="_blank" rel="nofollow">http://www.corejsf.com</a><br /> <br />Author: Graphic Java Series, Advanced JavaServerPages, Core JSTL and Core JavaServer Faces
Karthik Guru
Ranch Hand

Joined: Mar 06, 2001
Posts: 1209
Originally posted by David Geary:
but you'd have to mock a fair bit of the JSF implementation. The JSF Reference Implementation does that for internal testing.


David just one question: Has the RI released it as a public api, i mean the mocks that they use internally?
thanks
David Geary
Author
Ranch Hand

Joined: Apr 23, 2003
Posts: 45
The API for the mocks is not part of the spec. But the JSF 1.1_01 reference implementation is open source, so I believe you can get the source to the mocks if you want.
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Just curious, why would you want to Unit Test JSF UIComponents?


GenRocket - Experts at Building Test Data
David Geary
Author
Ranch Hand

Joined: Apr 23, 2003
Posts: 45
You want to unit test components for the same reason you unit test model beans: to make sure they're implemented according to their implicit design decisions and to make sure you don't inadvertently violate those decisions in the future.
Matt Raible
author
Ranch Hand

Joined: Jan 11, 2001
Posts: 114
Here's what I use to unit-test my managed beans:

BasePageTestCase:

https://appfuse.dev.java.net/nonav/source/browse/*checkout*/appfuse/extras/jsf/test/web/org/appfuse/webapp/action/BasePageTestCase.java?rev=HEAD

Simple testing of a bean - notice the getManagedBean() call in the setUp() method:

https://appfuse.dev.java.net/nonav/source/browse/*checkout*/appfuse/extras/jsf/test/web/org/appfuse/webapp/action/PasswordHintTest.java?rev=HEAD&content-type=text/plain


Matt<br /> <br />Author: <a href="http://springlive.com" target="_blank" rel="nofollow">Spring Live</a> and <a href="http://www.apress.com/book/bookDisplay.html?bID=256" target="_blank" rel="nofollow">Pro JSP</a><br />Weblogs: <a href="http://raibledesigns.com" target="_blank" rel="nofollow">Raible Designs</a> <a href="http://jroller.com/page/raible" target="_blank" rel="nofollow">Spring Live Blog</a>
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Unit Testability ---JSF