HTTPUNIT Test: The original code is: WebForm Form = response.getforms () [0]; Form.SetParameter ("UserName", "spreadParameter (" password "," ******** * "); // Request = form.getRequest (); response = browser.getResponse (Request); pass the test, because no jump to the previous page. Plan to WebForm Form = LoginPage.GetForms () [0]; WebRequest LoginRequest = form.getRequest (); LoginRequest.SetParameter ("UserName", UserName); LoginRequest.SetParameter ("Password", pass); will be in January 12 is verified. Several coding formats of the webpage: "UTF-8", "GBK", "ISO-8859-1", "Unicode", "UTF-16", "GB2312", "Unicodebig", "BIG5" about login test But I think it's because they didn't name the submit button. Specifically, Does Not Satisfy Regularity I thought about it carefully today, I feel that too many places are not very strict, and the test is difficult to pass. January 12 servlettestcase example, the target of the test is a servlet or any Java code that uses the servlet API.
Servlets, Any java code that uses Servlet API objectspublic void beginXXX (WebRequest theRequest) {// Set up HTTP related parameters theRequest.setURL ( "jakarta.apache.org", "/ mywebapp", "/test/test.jsp", Null, NULL; Therequest.addcookie ("Cookiename", "CookieValue");} public void testXXX () {MyServlettotest servlet = new myservlettotest (); servlet.init (config);
// Call method to test servlet.methodtotest ();
// Perform Some Server Side Asserts Assertequals ("SomeValue", session.getattribute ("somettribute"); assertequals ("jakarta.apache.org", request.getServerName ());}
Public void endxxx (WebRESPONSE THERESPONSE) {// asserts the returned http response.getCookie ("SomeCookie"); Assertequals ("SomeValue2", cookie.getValue ());
Assertequals ("Some Content Here", Theresponse.getText ());} jsptestcase is used to test normal tags, or any Java code for JSP API. FLITERTESTCASE is used to test fliter, or any Java code that uses the FLITER API.
Public void testxxx () throws servletexception, ioException
{
Samplefilter filter = new samplefilter ();
Config.setInitParameter ("Header", "
Config.setInitParameter ("Footer", "
FILTER.INIT (CONFIG)
Filterchain mockfilterchain = new filterchain () {
Public void Dofilter (servletRequest Therequest,
ServletResponse thereesponse) THROWS IOEXCEPTION, ServletException
{
PrintWriter Writer = thereponse.getwriter ();
Writer.print ("
some content p>);
Writer.close ();
}
Public void init (FilterConfig theconfig)
{
}
Public void destroy ()
{
}
}
Filter.dofilter (Request, Response, Mockfilterchain);
}
Public void endxxx (WebResponse theeresponse)
{
Assertequals ("
Some Content P>
Theresponse.getText ());
}