????JUnitPer????????

???????κ?????????????Σ?????????????????????????????????JUnitPer????????JUnit??????????????Σ??????????????????????????

????JUnitPer???????????????????????????????????????????TimedTest???LoadTest???У????潫??????????

????????????е????

???????JUnit???е??????

??????????????????????????????????TestCase????TestSuite??????TestCase????????????TestSuite?????????????????Vector????

??????Eclipse?????JUnit????

??????????????????JUnit????????????????????

package junit.samples;
import junit.framework.*;
/**
 * TestSuite that runs all the sample tests
 *
 */
public class AllTests {
       public static void main (String[] args) {
              junit.textui.TestRunner.run (suite());
       }
       public static Test suite ( ) {
              TestSuite suite= new TestSuite("All JUnit Tests");
              suite.addTest(VectorTest.suite());
              suite.addTest(new TestSuite(junit.samples.money.MoneyTest.class));
              suite.addTest(junit.tests.AllTests.suite());
           return suite;
       }
}


???????Cactus???????????????

?????????????ServletTestCase?????????????в?????????????

???????????? SampleServlet.java

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
public class SampleServlet extends HttpServlet
{
     public void saveToSession(HttpServletRequest request)
    {
         String testparam = request.getParameter("testparam");
         request.getSession().setAttribute("testAttribute"?? testparam);
     }


?????????? TestSampleServlet.java

import junit.framework.Test;
import junit.framework.TestSuite;
import org.apache.cactus.ServletTestCase;
import org.apache.cactus.WebRequest;
 
public class TestSampleServlet extends ServletTestCase
{
    public TestSampleServlet(String theName)
    {
        super(theName);
    }
 
    public static Test suite()
    {
        return new TestSuite(TestSampleServlet.class);
    }
 
    public void beginSaveToSessionOK(WebRequest webRequest)
    {
        webRequest.addParameter("testparam"?? "it works!");
    }
 
    public void testSaveToSessionOK()
    {
        SampleServlet servlet = new SampleServlet();
 
        servlet.saveToSession(request);
 
        assertEquals("it works!"?? session.getAttribute("testAttribute"));
 
    }
 
}