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:
There are no comments on this article