????????????????о?
???????????? ???????[ 2010/9/15 14:47:22 ] ????????
???????HTTPUnit???й??????
?????????Web???????????????????в????
?????????????????????????
????????????
????1??????????????????????????????????????????
????2????????????????????????檔
????3?????????????????????????????
????4??????????????????????????????????д???????????????LoginTestInfo??
publicinterface LoginTestInfo{
public void testValidPage() throws Exception;
public void testIsLoginPage() throws Exception;
public void testBadLogin() throws Exception;
public void testGoodLogin() throws Exception;
}
??????????Junit TestCase ?? implements LoginTestInfo ????
import java.net.URL;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import junit.textui.TestRunner; import com.meterware.httpunit.WebConversation;
import com.meterware.httpunit.WebRequest;
import com.meterware.httpunit.WebResponse;
import com.meterware.httpunit.WebForm;
import com.meterware.httpunit.GetMethodWebRequest;
public class LoginTest extends TestCase implements LoginTestInfo{
private WebConversation browser;
private WebRequest request;
private WebResponse response;
private String url = "http://localhost:8080/index.html";
public void setUp() throws Exception{
browser = new WebConversation();
request = new GetMethodWebRequest(url);
response = browser.getResponse(request);
}
//???????????????????????????????????????
public void testValidPage() throws Exception{
assertNotNull("localhost??????????????"??response);
}
//???????????????????????
public void testIsLoginPage() throws Exception{
URL currentUrl = response.getURL();
String currentUrlStr = currentUrl.getProtocol() + "://" +currentUrl.getHost() + currentUrl.getPath();
assertEquals("?????治??localhost???!" ??currentUrlStr??url);
}
//??????????????????????????
public void testBadLogin() throws Exception{
WebForm form = response.getForms()[0];
form.setParameter("userName"??"baduser");
form.setParameter("passWord"??"bad");
request = form.getRequest();
response = browser.getResponse(request);
assertTrue("?????????????????localhost??б???!"??response.getText().indexOf("localhost") != -1);
}
//??????????????????????????
public void testGoodLogin() throws Exception{
WebForm form = response.getForms()[0];
form.setParameter("userName"??"smile_xunn");
form.setParameter("passWord"??"*********");//????????д???????
request = form.getRequest();
response = browser.getResponse(request);
assertTrue("?????localhost??????????"??response.getText().indexOf("localhost") != -1);
}
public static TestSuite suite(){
return new TestSuite(LoginTest.class);
}
public static void main(String args[]){
TestRunner.run(suite());
}
}
???????????????????????????????????????????????????.
????Time: 7.203
????OK (4 tests)
????JMeter?????????
??????????JMeter????????????????????????????????ο?Apache?????
????JUnitPerf????????
???????????У?????????????????з??????????з??????????С?JUnitPerf?????е?JUnit?????????????????????????????????????????JUnitPerf????????????????????????????????????????????????????????
????????????
??????????????????????????????????????????????????????????????????ж???????????????????????????????????????Щ????????????????????μ???????????
???????????????????????????????????????????????????????????ú????????????????????????????????????????????????????γ???????????γ?????????????????????????????????????????????Щ??????????????????????£?????????????????
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11