使用JUnit&Ant生成UT报表

1. JUnit Test Case测试类需要从TestCase类继承

2. Ant的配置文件如下,添加一个target用来run JUnit并生成报表

<project default="report" basedir=".">
<target name="runtests">
<java fork="yes" classname="junit.textui.TestRunner"
taskname="junit" failonerror="true">
<arg value="unitTest.calculation.CalculationTest"/>
<classpath>
<pathelement location="Test.jar" />
<pathelement path="" />
</classpath>
</java>
</target>

<target name="report">

<junit printsummary="yes" fork="yes" haltonfailure="no" >
<classpath>
<fileset dir="../">
<include name="Test.jar" />
<include name="lib/test/hamcrest-core-1.1.jar" />
</fileset>
</classpath>
<formatter type="xml"/>
<test name="unitTest.calculation.calculationTest" todir="../report" />
</junit>

<junitreport todir="../report/html">
<fileset dir="../report">
<include name="TEST-unitTest.calculation.calculationTest.xml"/>

</fileset>
<report format="frames" todir="../report/html"/>
</junitreport>

</target>
</project>

3. 执行Ant生成一个html形式的报表

 

posted @ 2013-02-02 18:00  shileiw  阅读(388)  评论(0编辑  收藏  举报