3 Replies Latest reply on Oct 22, 2007 10:39 AM by ssilvert

    Unit testing my backing beans

    keefie

      Hi, my JSF app has backing beans which have dependencies on FacesContext and HttpSession. I want to write true unit tests for these beans, i.e. tests that run without a UI being involved, and without an app/web server running. Before I go down the path of trying to figure out how I can do this using a generic mock object framework I'd like to see if JSFUnit can meet my needs but I can't quite figure out where to start.

        • 1. Re: Unit testing my backing beans
          ssilvert

          You should start here:
          http://www.jsfunit.org

          JSFUnit is for in-container testing. It's very much like the Apache Cactus framework, but goes beyond it to support JSF constructs. IMHO, this is far better than using mock objects. With JSFUnit, you use a real FacesContext, the real HttpSession, the real JSF component tree, etc. So this way you don't need to worry about bugs and limitations in your mock objects.

          Your UI is not really involved in that you don't have to feed keystrokes to it or anything like that. The JSFUnitClientSession allows you to set params and do submits using a simple Java API.

          You do need to run a container, but you can configure things so that the container starts, tests run, and container stops as part of your build. It's very much like you are just running plain old JUnit tests. JSFUnit's own tests can be run this way. See this page http://labs.jboss.com/jsfunit/building-jsfunit.html for instructions on that.

          Hope that helps. Let me know if you have further questions.

          Stan

          • 2. Re: Unit testing my backing beans
            keefie

            Thanks for the reply, I'm not going to start a mock object debate. However, is it possible to edit your reply to remove the quote from a "JBoss rocks stars" as I find it offensive.

            • 3. Re: Unit testing my backing beans
              ssilvert

              I wasn't trying to offend anybody. I do realize that some people consider rock to be the Devil's music. :-)

              Have a nice day,

              Stan