#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2002
    Posts
    15
    Rep Power
    0

    java.lang.NoClassDefFoundError: junit.framework.TestCase


    I receive the following error while trying to access a servlet in Tomcat:

    java.lang.NoClassDefFoundError: junit.framework.TestCase

    I have the path to junit.jar setup in the classpath.

    Any ideas?

    Many thanks in advance

    ----------------------------------------------------------------------------------
    import junit.framework.*;
    import com.meterware.httpunit.*;
    public class SimpleRequest extends TestCase {
    WebConversation wc = new WebConversation();
    String base_url = "http://www.msn.com";
    public SimpleRequest(String name) {
    super(name);
    }
    public void testRequest() {
    WebResponse resp = null;
    try {
    resp = wc.getResponse( base_url );
    } catch (java.net.MalformedURLException e) {
    System.out.println("Bad url: " + e);
    } catch (java.io.IOException e) {
    System.out.println("IO Err: " + e);
    } catch (org.xml.sax.SAXException e) {
    System.out.println("XML Err: " + e);
    }
    assertEquals(200, resp.getResponseCode());
    }
    };
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2002
    Posts
    15
    Rep Power
    0
    It does run fine if I do the following command:

    java junit.textui.TestRunner SimpleRequest


    But why do I get the error while running via a web browser?

    P.S. I know that currently, no text would print to the browser, but in the future I could write code that would.
  4. #3
  5. No Profile Picture
    Clueless llama
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Feb 2001
    Location
    Lincoln, NE. USA
    Posts
    2,353
    Rep Power
    117
    The junit jar needs to be in the WEB-INF/classes folder for jsp's in Tomcat to find it. The environment variable CLASSPATH will not work.
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2002
    Posts
    15
    Rep Power
    0
    Thanks Nemi, that was easy :-)

    Now, I get the following error:

    root cause
    java.lang.InstantiationException: SimpleRequest

    any ideas?
  8. #5
  9. No Profile Picture
    Clueless llama
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Feb 2001
    Location
    Lincoln, NE. USA
    Posts
    2,353
    Rep Power
    117
    I am not familiar with junit, so I do not know what you are trying to do with it. Here is what the API docs say about that exception

    Thrown when an application tries to create an instance of a class using the newInstance method in class Class, but the specified class object cannot be instantiated because it is an interface or is an abstract class.

IMN logo majestic logo threadwatch logo seochat tools logo