輸入范例應用程序測試代碼
下載文章最后的 Download HtmlUnit_JavaSrc.zip 并將范例應用程序導入到您的 Java 項目。
運行測試案例
高亮顯示您需要進行測試的測試案例或測試序列,單擊 Run =>Run as =>JUnit 。
圖 3. 運行 JUnit
檢查測試結果
選擇 WebSphere Studio 中的 JUnit 視圖,您便可以查看運行結果了。
圖 4.JUnit HtmlUnit 測試結果
通過 Ant 腳本運行測試
<target name="htmlunit" depends="compile"> <junit printsummary="yes" haltonfailure="yes"> <classpath refid="junit.classpath"/> <formatter type="plain"/> <test name="sample.testcase.IBMEmployeeDirectoryPageTest" haltonfailure="no" outfile="test-result" todir="${build.dir}"> </test> </junit> </target> |
如果您尚未下載 HtmlUnit_JavaSrc.zip,請轉至本文的底部單擊 Download HtmlUnit_JavaSrc.zip 下載該文件。并修改 build.xml 文件,指定 build.dir 、 junit.jar 和 htmlunit.libdir 參數。
· 使用 Ant 配置 WebSphere Studio。選擇 Window =>Preferences 并單擊 Properties 。將 build.compiler 設置成 org.eclipse.jdt.core.JDTCompilerAdapter 。
圖 5. 為 Ant 進行 WebSphere Studio 配置
· 運行 Ant 腳本,運行結果將顯示在 WebSphere Studio 控制臺中。右鍵單擊 build.xml 并選擇 Run Ant 。運行結果將顯示在控制臺和 Ant 輸出文件中。