JUnitReport的使用 .

来源:互联网 发布:全景通系统源码 编辑:程序博客网 时间:2024/06/14 08:55
……<!-- =================================           target: test                       ================================= -->    <target name="test" depends="compile" description="description">    <mkdir dir="${target.report.dir}"/>        <junit printsummary="yes" haltonerror="yes" haltonfailure="yes" fork="yes">        <formatter type="plain" usefile="false"/>        <formatter type="xml"/>        <test name="junitbook.sampling.TestDefaultController" todir="${target.report.dir}" />        <classpath>        <pathelement location="${target.classes.java.dir}"/>        <pathelement location="${target.classes.test.dir}"/>        </classpath>        </junit>    </target><!-- =================================           target: report                       ================================= -->    <target name="report" depends="test" description="generate report">        <mkdir dir="${target.report.dir}/html"/>    <junitreport todir="${target.report.dir}">    <fileset dir="${target.report.dir}">    <include name="TEST-*.xml"/>    </fileset>    <report todir="${target.report.dir}/html"/>    </junitreport>    </target>……


 

junitreport被设计用来以XML文档的形式输出测试结果,通过XSL样式表转化成HTML。

 

自动找出要运行的测试

<!-- =================================           target: test                       ================================= --><target name="test" depends="compile" description="description"><mkdir dir="${target.report.dir}"/><property name="tests" value="Test*"/><junit printsummary="yes" haltonerror="yes" haltonfailure="yes" fork="yes"><formatter type="plain" usefile="false"/><formatter type="xml"/><batchtest todir="${target.report.dir}"><fileset dir="${src.test.dir}"><include name="**/${tests}.java" /><exclude name="**/Test*All.java"/></fileset></batchtest><test name="junitbook.sampling.TestDefaultController" todir="${target.report.dir}" /><classpath><pathelement location="${target.classes.java.dir}"/><pathelement location="${target.classes.test.dir}"/></classpath></junit></target>


 

这里第6行指定一个property,而不是在第12行直接使用通配符来完成。因为这样做有个好处,就是你可以使用命令行定义测试属性和运行单独的一个测试(或者特定的测试集)。当然,最后,你可以运行整套测试,以保证所有的测试都在同一页上。下面是执行TestDefaultController测试案例的例子:

ant -Dtests=TestDefaultController test

 

 

 

原创粉丝点击