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> </target>
上面的例子显示的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