Currently Being Moderated

JSFUnitTestClass

VERSION 6

Created on: Nov 6, 2007 10:40 AM by Stan Silvert - Last Modified:  Nov 7, 2007 9:53 PM by Stan Silvert

A JSFUnit Test Class is an ordinary JUnit class.  However, it does need to extend org.apache.cactus.ServletTestCase which extends junit.framework.TestCase.

 

Here is a simple example:


import java.io.IOException;
import org.apache.cactus.ServletTestCase;
import org.jboss.jsfunit.facade.JSFClientSession;
import org.jboss.jsfunit.facade.JSFServerSession;
import org.xml.sax.SAXException;

public class MyJSFUnitTest extends ServletTestCase
{
   private JSFClientSession client;
   private JSFServerSession server;

   // JUnit suite() method
   public static Test suite()
   {
      return new TestSuite( MyJSFUnitTest.class );
   }

   // optional JUnit setUp() method
   public void setUp() throws IOException, SAXException
   {    
      this.client = new JSFClientSession("/hello.jsf");
      this.server = new JSFServerSession(client);
   }

   // one or more JUnit test methods
   public void testHelloWorld() throws IOException, SAXException
   {
      client.setParameter("name", "Stan");
      client.submit();
      assertEquals("Stan", server.getManagedBeanValue("#{myBean.name}"));
      assertTrue(client.getWebResponse().getText().contains("Hello, Stan"));
   }
} 

 

 

 

 

Referenced by:

 

 

 

Average User Rating
(0 ratings)




There are no comments on this article

More Like This

  • Retrieving data ...

Incoming Links