เขายกตัวอย่างใน post Lift Off
เปรียบเทียบวิธีเดิมที่ใช้ HttpUnit เทียบกับที่ใช้ Lift
HttpUnit
public class HttpUnitGoogleTest extends TestCase {
public void testGoogleImageSearch() throws Exception {
WebConversation conversation = new WebConversation();
WebResponse page = conversation.getResponse("http://www.google.com/");
assertEquals(page.getTitle(), "Google");
page = page.getLinkWith("Images").click();
WebForm form = page.getForms()[0];
form.setParameter("q", "kizoom");
page = form.submit();
assertTrue(page.getText().contains("<b>Kizoom</b> summer party"));
boolean foundImage = false;
for (WebImage i : page.getImages()) {
if (i.getSource().endsWith("summer04.jpg")) {
foundImage = true;
break;
}
}
assertTrue(foundImage);
}
}
Lift
public class GoogleTest extends NavigatingLiftTestCase {
public void testGoogleImageSearch() throws Exception {
goTo("http://www.google.com/");
assertThat(page, has(title("Google")));
clickOn(link("Images"));
enter("kizoom", into(textField()));
clickOn(button("Search Images"));
assertThat(page, has(text("Kizoom summer party")));
assertThat(it, has(image().withUrlThat(endsWith("summer04.jpg"))));
}
}
No comments:
Post a Comment