|
homepage
JWebUnit is a Java-based testing framework for web applications. It wraps existing testing frameworks such as HtmlUnit and Selenium with a unified, simple testing interface to allow you to quickly test the correctness of your web applications.
看下使用吧。
下载jar包
引入jwebunit-htmlunit-plugin-2.3.jar,jwebunit-core-2.3.jar
注意lib里面jar包也要引入
例子1(HtmlUnit)- package com.test;
- import net.sourceforge.jwebunit.htmlunit.HtmlUnitTestingEngineImpl;
- import net.sourceforge.jwebunit.junit.WebTestCase;
- import net.sourceforge.jwebunit.junit.WebTester;
- import net.sourceforge.jwebunit.selenium.SeleniumTestingEngineImpl;
- public class ExampleWebTestCase extends WebTestCase {
- private WebTester tester;
-
- public ExampleWebTestCase(String name) {
- super(name);
- tester = new WebTester();
- HtmlUnitTestingEngineImpl engine = new HtmlUnitTestingEngineImpl();
- //SeleniumTestingEngineImpl engine = new SeleniumTestingEngineImpl();
- tester.setDialog(engine);
- tester.getTestContext().setBaseUrl("http://www.google.cn/");
- }
- public void testSearch() throws Exception {
- tester.beginAt("/");
- tester.setTextField("q", "HtmlUnit");
- tester.submit("btnG");
- tester.clickLinkWithText("HtmlUnit");
- tester.assertTitleEquals("HtmlUnit - Google 搜索");
- tester.assertLinkPresentWithText("Get started");
- }
- }
复制代码 例子2(selenium)
在运行这个例子这前:1.要下载selenium-jwebunit-plugin.jar包;2.启动selenium server;3.引入selenium-client.jar包- package com.test;
- import net.sourceforge.jwebunit.htmlunit.HtmlUnitTestingEngineImpl;
- import net.sourceforge.jwebunit.junit.WebTestCase;
- import net.sourceforge.jwebunit.junit.WebTester;
- import net.sourceforge.jwebunit.selenium.SeleniumTestingEngineImpl;
- public class ExampleWebTestCase extends WebTestCase {
- private WebTester tester;
-
- public ExampleWebTestCase(String name) {
- super(name);
- tester = new WebTester();
- //HtmlUnitTestingEngineImpl engine = new HtmlUnitTestingEngineImpl();
- SeleniumTestingEngineImpl engine = new SeleniumTestingEngineImpl();
- tester.setDialog(engine);
- tester.getTestContext().setBaseUrl("http://www.google.cn/");
- }
- public void testSearch() throws Exception {
- tester.beginAt("/");
- tester.setTextField("q", "HtmlUnit");
- tester.submit("btnG");
- tester.clickLinkWithText("HtmlUnit");
- tester.assertTitleEquals("HtmlUnit - Google 搜索");
- tester.assertLinkPresentWithText("Get started");
- }
- }
复制代码 这个工具没有怎么用,只是看到这个工具处理方面。在setup中来设置用什么测试工具来执行。在一个项目中使用多种测试工具时,是否有参考意义呢?
用htmlunit是没有界面,明显比selenium要快。 |
|