Ant Junit集成
JUnit 是基於Java常用的單元測試框架進行開發。它是易於使用和易於延伸。有許多JUnit擴展可用。如果你不熟悉Junit的,你應該從www.junit.org下載JUnit和閱讀JUnit的使用手冊。
本教程討論了關於執行使用Ant 的JUnit測試。Ant 通過這個簡單Junit 的任務變得簡單。
以下展示的是JUnit 任務的屬性。
Properties
描述
dir
Where to invoke the VM from. This is ignored when fork is disabled.
jvm
Command used to invoke the JVM. This is ignored when fork is disabled.
fork
Runs the test in a separate JVM
errorproperty
The name of the property to set if there is a Junit error
failureproperty
The name of the property to set if there is a Junit failure
haltonerror
Stops execution when a test error occurs
haltonfailure
Stops execution when a failure occurs
printsummary
Advices Ant to display simple statistics for each test
showoutput
Adivces Ant tosend the output to its logs and formatters
tempdir
Path to the temporary file that Ant will use
timeout
Exits the tests that take longer to run than this setting (in milliseconds).
讓我們繼續的Hello World fax web應用程序的主題,並添加一個JUnit目標。
下面的例子展示了一個簡單的JUnit測試執行
<target name="unittest"> <junit haltonfailure="true" printsummary="true"> <test name="com.yiibai.UtilsTest"/>
上面的例子顯示的Junit對com.yiibai.UtilsTest JUnit類執行。運行上面會產生下面的輸出
test: [echo] Testing the application [junit] Running com.yiibai.UtilsTest [junit] Tests run: 12, Failures: 0, Errors: 0, Time elapsed: 16.2 sec
BUILD PASSED