Referencing the FacesContext
directly in Java classes makes managed beans more difficult to unit
test. This post discusses how to mock the context for testing outside
the application container.
These examples use Mockito with JUnit. Familiarity with JSF and unit testing Java is assumed.
I've used thejavax.faces.bean
annotations but the
techniques apply for other bean management mechanisms (e.g. using faces-config.xml
or Spring).