现在的位置: 首页 > 综合 > 正文

JUnit和ant结合

2013年10月15日 ⁄ 综合 ⁄ 共 1334字 ⁄ 字号 评论关闭


JUnit和ant结合
cherami 转贴 

ant 提供了两个 target : junit 和 junitreport  
运行所有 测试用例 ,并生成 html 格式的报表 
具体操作如下: 

1.将 junit.jar 放在 ANT_HOME/lib 目录下 
2.修改 build.xml ,加入如下 内容: 

    <property name="report" value="report" /> 

    <target name="junitreport" depends="clean, compile"
        <junit printsummary="on" 
                fork="true" 
                haltonfailure="false" 
                failureproperty="tests.failed" 
                showoutput="true"
            <classpath refid="myclasspath"/> 
            <formatter type="xml"/> 
            <batchtest todir="${report}"
                <fileset dir="${build}"
                    <include name="**/*Test.*"/> 
                </fileset> 
            </batchtest> 
        </junit> 
        <junitreport todir="${report}"
            <fileset dir="${report}"
                <include name="TEST-*.xml"/> 
            </fileset> 
            <report format="frames" todir="${report}"/> 
        </junitreport> 
        <fail if="tests.failed"
            --------------------------------------------------------- 
            One or more tests failed, check the report for detail... 
            --------------------------------------------------------- 
        </fail> 
    </target> 

运行 这个 target ,ant 会运行每个 TestCase  
在 report 目录下就有了 很多 TEST*.xml 和 一些网页 
打开 report 目录下的 index.html 就可以看到很直观的测试运行报告,一目了然。

【上篇】
【下篇】

抱歉!评论已关闭.