I am trying to implement JUnit unit testing using a ServletUnit to test a servlet, specifically a java file named SignedNotesServlet.java . This test class is in the same directory as SignedNotesServlet.java . I am using Eclipse.
However, I am having trouble writing the correct syntax for registerServlet method that is part of ServletUnit and HttpUnit. I have not yet run the program. The errors I am receiving are
Syntax error on tokens, FormalParameter expected instead
Syntax error on token "class", identifier expected
Syntax error on token(s), misplaced construct(s)
Syntax error on token ""SignedNotesServlet"", invalid FormalParameterList
Here is my code:
package notetaker;
import com.meterware.servletunit.ServletRunner;
import com.meterware.servletunit.ServletUnitClient;
import com.meterware.httpunit.GetMethodWebRequest;
import com.meterware.httpunit.WebRequest;
import com.meterware.httpunit.WebResponse;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.fail;
public class SignedNotesServletTest {
ServletRunner sr = new ServletRunner();
sr.registerServlet( "SignedNotesServlet", SignedNotesServlet.class.getName() );
private SignedNotesServlet signednotes;
@Test
public void test() {
fail("Not yet implemented");
}
}
I think I correctly added the jar file the buildpath, using instructions from http://tinyurl.com/ku7huss . I used http://tinyurl.com/b55fn as my main reference but am also looking at the few registerServlet examples on the web (I can't post those links for reference since I need a 10 reputation to post more than 2 links). I am not entirely sure what could be wrong since I basically copy-pasted from the second website and made (what I thought) were appropriate changes.
I also thought that maybe something was wrong with "SignedNotesServlet" since there were quadruple quotes in the error, and I removed them, but it still doesn't work out, and I don't think that would have been correct syntax anyway, based on the examples.