知识大全 Ant+JUnit+Cobertura

Posted 文件

篇首语:不患人之不己知,患不知人也。本文由小常识网(cha138.com)小编为大家整理,主要介绍了知识大全 Ant+JUnit+Cobertura相关的知识,希望对你有一定的参考价值。

Java应用利器组合:Ant+JUnit+Cobertura  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!

  看标题就知道 这个是开发一个Java应用的利器组合 使用Ant完成工程的构建(Build) 使用JUnit完成单元测试 使用Cobertura完成代码覆蓋测试 也可以辅助查找性能瓶颈和一些类型的BUG 下面是一个完整的build xml范例 可以完全拿来用 不需任何修改 只要你的目录和这里的目录一致(应该也是很通用的)

  下载下面的build xml文件

  文件内容 <project default= all >    <!– =================================================================== –>    <!–                               Definitions                           –>    <!– =================================================================== –>        <property name= base dir location= />    <property name= lib dir location= $base dir/lib />    <property name= src dir location= $base dir/src />    <property name= testcase dir location= $base dir/test />    <property name= out dir location= $base dir/classes />    <property name= report dir location= $base dir/report />    <property name= junit dir location= $report dir/junit />    <property name= junit xml dir location= $junit dir/xml />    <property name= junit dir location= $junit dir/ />    <property name= cobertura dir location= $report dir/cobertura />    <property name= cobertura xml dir location= $cobertura dir/xml />    <property name= cobertura dir location= $cobertura dir/ />    <property name= instrumented dir location= $report dir/instrumented />    <property name= instrument file location= $instrumented dir/cobertura ser />    <property name= cobertura dir value= $instrumented dir />            <path id= classpath all >        <pathelement location= $out dir />        <fileset id= alljars dir= $lib dir >            <include name= **/* jar />        </fileset>    </path>

  <!– include the cobertura building jars –>      <path id= cobertura classpath >        <path refid= classpath all />    </path>            <!– define the cobertura property file –>      <taskdef classpat resource= tasks properties />        <!– =================================================================== –>    <!–                            Project Targets                          –>    <!– =================================================================== –>        <target name= init description= initialize the project env >        <!– create the output folder –>          <mkdir dir= $out dir />        <mkdir dir= $report dir />        <copy todir= $out dir >            <fileset dir= $src dir includes= **/* properties />        </copy>    </target>

  <target name= pile depends= init >        <javac srcdir= $src dir destdir= $out dir >            <classpath refid= classpath all />        </javac>    </target>       <!– =================================================================== –>    <!–                            Unit Test Targets                        –>    <!– =================================================================== –>        <!–       target: init      initialize the build env                 –>        <target name= init test description= initialize the test env >        <!– create the output folder –>          <mkdir dir= $junit dir />        <mkdir dir= $junit xml dir />        <mkdir dir= $junit dir />    </target>

  <!–       target: pile test      pile the test cases                     –>         <target name= pile test depends= pile >        <javac srcdir= $testcase dir destdir= $out dir >                   <classpath refid= classpath all />        </javac>    </target>

  <!– =================================       target: test      run the unit test     ================================= –>        <target name= test depends= init test >        <junit fork= yes printsummary= on maxmemory= m >            <sysproperty key= bertura datafile                 file= $instrument file />

  <classpath location= $instrumented dir />            <classpath refid= cobertura classpath />                               <formatter type= xml />            <batchtest todir= $junit xml dir >                <fileset dir= $out dir >                    <include name= **/Test* class />                    <exclude name= **/*$* class />                </fileset>            </batchtest>        </junit>        <junitreport todir= $junit xml dir >            <fileset dir= $junit xml dir >                <include name= TEST * xml />            </fileset>            <report format= frames todir= $junit dir />        </junitreport>    </target>        <!– =================================================================== –>    <!–                      Code Coverage Targets                          –>    <!– =================================================================== –>   

  <!–       target: init      initialize the build env for code coverage                          –>        <target name= init coverage description= initialize the build env >        <!– create the output folder –>          <mkdir dir= $instrumented dir />        <mkdir dir= $cobertura dir />        <mkdir dir= $cobertura xml dir />        <mkdir dir= $cobertura dir />    </target>        <target name= pile coverage depends= init >        <javac srcdir= $src dir:$testcase dir destdir= $out dir debug= true >              <classpath refid= cobertura classpath />        </javac>    </target>

  <!– =================================       target: instrument      Instrument into the class files but      exclude test classes     ================================= –>         <target name= instrument depends= init coverage pile coverage description= instrument into the class files >        <!–          Instrument the application classes writing the          instrumented classes into $instrumented dir         –>        <cobertura instrument todir= $instrumented dir datafile= $instrument file >            <!–                The following line causes instrument to ignore any                source line containing a reference to log j for the                purposes of coverage reporting             –>            <ignore regex= apache log j * />            <fileset dir= $out dir >                <!–                   Instrument all the application classes but                  don t instrument the test classes                 –>                <include name= **/* class />                <exclude name= **/Test* class />            </fileset>        </cobertura instrument>    </target>                <!– =================================       target: coverage check      check the code coverage by given rates      ================================= –>      <target name= coverage check description= check the code coverage by given rates >      <cobertura check branchrate= totallinerate= />    </target>        <!– =================================       target: coverage report xml      generate code coverage report by xml format     ================================= –>          <target name= coverage report xml description= generate xml report >      <!– Generate an XML file containing the coverage data using the srcdir attribute –>      <cobertura report srcdir= $src dir destdir= $cobertura xml dir format= xml datafile= $instrument file />    </target>        <!– =================================       target: coverage report       generate code coverage report by format     ================================= –>        <target name= coverage report >    <!–        Generate a series of HTML files containing the coverage        data in a user readable form using nested source filesets     –>      <cobertura report destdir= $cobertura dir datafile= $instrument file >        <fileset dir= $src dir >          <include name= **/* java />        </fileset>      </cobertura report>    </target>        <!– run the code coverage individual –>    <target name= coverage depends= pile coverage instrument test coverage report         description= Compile instrument ourself run the tests and generate JUnit and code coverage reports />        <!– =================================================================== –>    <!–                           Public Targets                            –>    <!– =================================================================== –>        <target name= clean >        <delete quiet= true includeEmptyDirs= true >            <fileset dir= $report dir >                <exclude name= cvsignore />                <exclude name= CVS />            </fileset>            <fileset dir= $out dir >            </fileset>        </delete>    </target>            <!– =================================================================== –>    <!–                           Global Targets                            –>    <!– =================================================================== –>        <target name= all depends= pile />         <target name= junit depends= clean pile test test />

  <target name= full depends= clean coverage />

  </project>

作者: Cherami原载: Ant+JUnit+Cobertura 版权所有 转载时必须以链接形式注明作者和原始出处及本声明 cha138/Article/program/Java/ky/201311/28089

相关参考

知识大全 使用Ant编译、运行Junit、以及检查编码[3]

使用Ant编译、运行Junit、以及检查编码[3]  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!&

知识大全 使用Ant编译、运行Junit、以及检查编码[2]

使用Ant编译、运行Junit、以及检查编码[2]  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!&

知识大全 使用Ant编译、运行Junit、以及检查编码[1]

使用Ant编译、运行Junit、以及检查编码[1]  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!&

知识大全 使用Ant编译、运行Junit、以及检查编码[4]

使用Ant编译、运行Junit、以及检查编码[4]  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!&

知识大全 ant结合junit进行软件自动测试

   持续集成实践三灵感来自于MartinFowler的持续集成一文可以在martinfowler看到国内有人翻译成了中文   本文假设读者

知识大全 一些错误地解决方法

如果使用Ant和Junit是被报找不到test检查一下是否误用了private出错信息   <failuremessage=NotestsfoundintestAl

知识大全 JUnit测试建议

JUnit测试建议  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!  以下是对JUnit实践的一个很

知识大全 JUnit的各种断言

JUnit的各种断言  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!  JUnit为我们提供了一些辅

知识大全 Junit4功能介绍

Junit4功能介绍  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!  JUnit是JAVA语言事实

知识大全 JUnit起步

JUnit起步  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!   如