junit和cobertura在spring框架下进行单元测试和生成报告_第1页
全文预览已结束

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、junit和cobertura在spring框架下进行单元测试和生成报告在前面两篇文章中分离讲解了junit 和cobertura的集成应用,以及如何在spring环境下举行单元测试,现在如何将cobertura集成到spirng环境中,其实很容易,无非在执行cobertura的ant脚本时,将spring加载用到的配置文件复制到cobertura编译的class文件中,配置如下: ?xml version="1.0" eoding="utf-8"? project name="cobertura.amples.basic" defa

2、ult="coverage" basir="." description cobertura - copyright (c) 2003 jcoverage ltd. copyright (c) 2005 mark doliner thekingant cobertura is licen under the gnu general public license cobertura comes with absolutely no warranty /description property ="perties" /

3、!-it need all the lib of project- property name="project.lib.dir" loion="./webcontent/web-inf/lib" / !- cobertura lib path - path ="cobertura.classpath" file dir="$cobertura.dir" include name="lib/*.jar" / /fileset /path !- project lib path - path id

4、="project.classpath" fileset dir="$project.lib.dir" include name="*.jar" / /fileset /path taskdef classpathref="cobertura.classpath" resource="perties"/ !-clean task- target name="clean" description="remove all files created b

5、y the build/test process." delete dir="$classes.dir" / delete dir="$insumented.dir" / delete dir="$reports.dir" / delete file="cobertura.log" / delete file="cobertura.ser" / /target !-int task- target name="init" description="crea

6、te of the report and copy the config files needed by the project." dir="$classes.dir" / mkdir dir="$instrumented.dir" / mkdir dir="$reports.xml.dir" / mkdir dir="$reports.html.dir" / mkdir dir="$coverage.xml.dir" / mkdir dir="$coverage.html

7、.dir" / !-copy all the config files to the compile path- copy includeemptydirs="fae" todir="$classes.dir" fileset dir="./src/main/resources" exclude name="*/*.launch"/ exclude name="*/*.java"/ exclude name="*/*.java"/ /fileset /copy /t

8、arget !-compile task- target name="compile" depends="init" javac encoding="utf-8" srir="$src.dir" destdir="$classes.dir" debug="true" classpath path refid="project.classpath"/ path refid="cobertura.classpath"/ /classpath

9、 /javac javac srcdir="$test.dir" destdir="$classes.dir" debug="true" classpath path refid="project.classpath"/ path refid="cobertura.classpath"/ /classpath /javac /target target name="instrument" depends="init,compile" !- remove t

10、he coverage data file and any old instrumentation. - delete file="cobertura.ser"/ delete dir="$instrumented.dir" / !- instrument the application classes, writing the instrumented classes into $build.instrumented.dir. - cobertura-instrument todir="$instrumented.dir" !- t

11、he following line causes instrument to ignore any source line containing a reference to log4j, for the purposes of coverage reporting. - ignore regex="org.apache.log4j.*" / fileset dir="$classes.dir" !- instrument all the application classes, but don't instrument the test cla

12、sses. * - include name="com/morningstar/planning/*/*.class" / exclude name="com/morningstar/planning/*/i*.class" / exclude name="com/morningstar/planning/*/*test.class" / exclude name="com/morningstar/planning/dao/pport/simpledaosupport.class" / exclude name=&

13、quot;com/morningstar/planning/base/abstracttestcase.class" / /fileset /cobertura-instrument /target target name="test" depends="init,compile" junit fork="yes" dir="$basedir" failureproperty="test.failed" !- note the classpath order: instrumented

14、 classes are before the original (uninstrumented) classes. this is important. - classpath location="$instrumented.dir" / classpath location="$classes.dir" / !- the instrumented classes reference classes used by the cobertura run, so cobertura and its dependencies must be on your

15、classpath. - classpath refid="project.classpath" / classpath refid="cobertura.classpath" / foatter type="xml" / test name="$testcase" todir="$reports.xml.dir" if="testcase" / batchtest todir="$reports.xml.dir" un="testcase&qu

16、ot; fileset dir="$test.dir" !- instrument all the test classes, but don't instrument the application classes. * - include name="com/morningstar/planning/*/*test.java" / exclude name="com/morningstar/planning/dao/recordtest.java" / /fileset /batchtest /junit junitrep

17、ort todir="$reports.xml.dir" fileset dir="$reports.xml.dir" include name="test-*.xml" / /fileset report format="frames" todir="$reports.html.dir" / /junitreport /target target name="coverage-check" cobertura-check branchrate="34"

18、totallinerate="100" / /target target name="coverage-report" !- generate an xml file containing the coverage data using the "srcdir" attribute. - cobertura-report srcdir="$src.dir" destdir="$coverage.xml.dir" format="xml" / /target target name="alternate-coverage-report" !- generate a series of html files containing the coverage data in a user-readable form using nested source filesets. - cobertura-report destdir="$coverage.html.dir" fileset dir="$src.dir" include name="*/*.java&qu

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论