Behaviour-driven development is a great way to design and build the web layers of your application. In this article, I look at how to use JWebUnit, a fast and light-weight web testing framework, with Easyb, a powerful Groovy-based BDD framework.
JWebUnit is a web testing framework built on HTMLUnit. It runs in memory, so it's fast. However, it also has an intuitive, high-level API, making it easy to use even if you have only an approximate idea of the exact HTML details of your application screens. A simple JWebUnit test case is shown here:
import net.sourceforge.jwebunit.junit.WebTestCase;
import net.sourceforge.jwebunit.junit.WebTester;
public class TestJWebUnitDepositStoryUI extends WebTestCase {
public void setUp() {
setBaseUrl("http://localhost:9090/ebank-web");
}
public void testDepositingCashShouldAddToBalance() {
beginAt("/");
assertTextPresent("Current Balance: $0");
setTextField("depositAmount","100");
clickButtonWithText("deposit");
assertTextPresent("Current Balance: $100");
}
}
详细链接如下:http://www.wakaleo.com/component/content/article/183