HttpUnit: 웹 사이트에 대한 단위 테스트 프레임워크 :: 2007/09/25 02:00
|
|
http://httpunit.sourceforge.net/
위의 URL이 httpunit의 주소입니다. jUnit과 함께 사용해야하는, Java 기반의 solution입니다.
Cookbook 문서를 읽어보면 알수 있는 것입니다만 (아래의 글은 Cookbook 문서를 보고 간단히 요약한 것입니다) HttpUnit 프레임워크는 WebConversion 클래스를 사용해서 웹 브라우저가 만드는 HTTP conversion을 흉내냅니다.
WebConversation wc = new WebConversation();
WebRequest req = new GetMethodWebRequest( "http://www.meterware.com/testpage.html" );
WebResponse resp = wc.getResponse( req );
WebRequest req = new GetMethodWebRequest( "http://www.meterware.com/testpage.html" );
WebResponse resp = wc.getResponse( req );
WebResponse 객체를 받아온 다음에는 getText() 메소드를 불러서 텍스트 형태의 프로세싱을 할 수도 있고, getDOM() 메소드를 호출해서 DOM 기반의 조작을 할 수도 있습니다. (이 편이 좀 더 편하긴 하겠네요.)
다음 처럼 하면 링크를 따라가는 것도 가능합니다.
WebConversation wc = new WebConversation();
WebResponse resp =
wc.getResponse( "http://www.httpunit.org/doc/cookbook.html" ); // read this page
WebLink link = resp.getLinkWith( "response" ); // find the link
link.click(); // follow it
WebResponse jdoc = wc.getCurrentPage(); // retrieve the referenced page
WebResponse resp =
wc.getResponse( "http://www.httpunit.org/doc/cookbook.html" ); // read this page
WebLink link = resp.getLinkWith( "response" ); // find the link
link.click(); // follow it
WebResponse jdoc = wc.getCurrentPage(); // retrieve the referenced page
폼 프로세싱이나 테이블 형태의 자료 처리도 가능합니다. 폼 프로세싱 예제만 살펴보면,
WebForm form = resp.getForms()[0]; // select the first form in the page
assertEquals( "La Cerentolla", form.getParameterValue( "Name" ) );
assertEquals( "Chinese", form.getParameterValue( "Food" ) );
assertEquals( "Manayunk", form.getParameterValue( "Location" ) );
assertEquals( "on", form.getParameterValue( "CreditCard" ) );
assertEquals( "La Cerentolla", form.getParameterValue( "Name" ) );
assertEquals( "Chinese", form.getParameterValue( "Food" ) );
assertEquals( "Manayunk", form.getParameterValue( "Location" ) );
assertEquals( "on", form.getParameterValue( "CreditCard" ) );
위와 같이 해서 폼의 기본 파라메타 값이 어떻게 만들어져있는지 검사할 수도 있고,
form.setParameter( "Food", "Italian" ); // select one of the permitted values for food
form.removeParameter( "CreditCard" ); // clear the check box
form.submit(); // submit the form
form.removeParameter( "CreditCard" ); // clear the check box
form.submit(); // submit the form
폼에 포함된 컨트롤들에 값을 넣어서 날릴 수도 있습니다.
웹 기반의 인터페이스 테스트를 하는 데 굉장히 유용할 것 같네요. :-) 하지만 이 프레임워크의 가장 큰 약점은...
자바스크립트 지원이 아직은 기본적인 수준이다
는 점이 되겠군요 -_-;
다들 알고 있는데 저만 모르는 사실들이 아주 많은것 같아 좀 우울합니다 ㅋㅋ
|
|
트랙백 주소 :: http://www.buggymind.com/trackback/50





