• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Unit Testability ---JSF

 
Mcgill Smith
Ranch Hand
Posts: 178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In JSF can Components be tested independently as pure java objects?



Thanks
 
David Geary
Author
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Karthik Guru
Ranch Hand
Posts: 1209
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just curious, why would you want to Unit Test JSF UIComponents?
 
David Geary
Author
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 114
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic