File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Testing and the fly likes Testing Servlets Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Testing
Bookmark "Testing Servlets" Watch "Testing Servlets" New topic

Testing Servlets

Manohar Karamballi
Ranch Hand

Joined: Jul 17, 2001
Posts: 227
I have newbie these testing Unit world..
I am facing following problem in using servlet unit.
my testcase code..

public class ODDSControllerSTest extends TestCase
public static void main(String args[])
{ suite() );
public static Test suite()
return new TestSuite( ODDSControllerSTest.class );

public ODDSControllerSTest( String name )
super( name );
public void testHeader() throws Exception
WebConversation conversation = new WebConversation();
WebRequest request = new GetMethodWebRequest( "http://localhost:8080/LNT/ODDSControllerS" );
WebResponse response = conversation.getResponse( request );
assertEquals("Response failed",200,response.getResponseCode());


//import junit related classes
import com.meterware.servletunit.*;
import com.meterware.httpunit.*;
import junit.framework.*;
//import javax related classes
import javax.servlet.ServletOutputStream;
//import java related classes
public class LNTControllerSTest extends TestCase
public void testForwardToRetrieveJSP() throws Exception
ServletRunner sr = new ServletRunner( "web.xml" );
ServletUnitClient client = sr.newClient();
@ line2 that is getting client ,am getting error
pls help me out

It is sorta covered in the JavaRanch Style Guide.
subject: Testing Servlets
jQuery in Action, 3rd edition