當然,在實際應用中你需要根據不同的需要來選擇不同的endXXX。兩個WebResponse的差別可以參見兩者各自的API Doc,這里就不再多說了。
如何在Cactus里寫測試
. 寫測試代碼
首先,我們給出被測類的代碼,是一個Servlet:
public class SampleServlet extends HttpServlet {
public void doGet(HttpServletRequest theRequest,
HttpServletResponse theResponse) throws IOException {
PrintWriter pw = theResponse.getWriter();
theResponse.setContentType("text/html");
pw.print("<html><head/><body>");
pw.print("A GET request");
pw.print("</body></html>");
}
public String checkMethod(HttpServletRequest theRequest) {
return theRequest.getMethod();
}
}
Cactus中的測試類框架已經在上面給出。下面來看一下例子,例子是從中Cactus自帶的實例中抽取的一部分,如下:
public class TestSampleServlet extends ServletTestCase {
文章來源于領測軟件測試網 http://www.kjueaiud.com/