关于jUnit+ant生成测试报告问题

请叫我砖家 2013-11-10 12:33:37
我现在在利用jUnit+ant生成测试报告,写好jUnit后,进行测试,发现测试成功,并且数据库里添加了这条信息。但是在利用cmd进入ant进行测试后,生成的测试报告却说测试不成功,为什么两种测试的结果会出在哪里?问题原因是怎样?build.xml配置错误吗?请各位高手帮忙解答一下,多谢!~~

<?xml version="1.0" encoding="UTF-8"?>
<!-- 默认执行coverage -->
<project name="cobertura.examples.basic" default="coverage" basedir=".">
<description>
Cobertura - http://cobertura.sourceforge.net/
Copyright (C) 2003 jcoverage ltd.
Copyright (C) 2005 Mark Doliner <thekingant@users.sourceforge.net>
Copyright (C) 2006 Dan Godfrey
Cobertura is licensed under the GNU General Public License
Cobertura comes with ABSOLUTELY NO WARRANTY
</description>

<!-- 引入 -->
<property file="build.properties" />
<path id="cobertura.classpath">
<fileset dir="lib">
<!--<include name="cobertura*.jar" />-->
<include name="*.jar" />
</fileset>
</path>
<!--
配置 cobatura ant 扩展任务
(taskdef 元素将 cobertura.jar 文件限定在当前工作目录中)
-->
<taskdef classpathref="cobertura.classpath" resource="tasks.properties"/>
<!-- 初始化 -->
<target name="init">
<!-- 删除地址 -->
<delete dir="${classes.dir}"/>
<delete dir="${antReoprt.dir}"/>
<!-- 创建地址 -->
<mkdir 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.summaryxml.dir}" />
<mkdir dir="${coverage.html.dir}" />
</target>

<!-- 编译(init完成后执行) -->
<target name="compile" depends="init">
<javac srcdir="${test.dir}" destdir="${classes.dir}" debug="yes">
<sourcepath path="${src.dir}"></sourcepath>
<classpath refid="cobertura.classpath" />
</javac>
</target>
<!--
该任务将在已经编译好的类文件中添加日志代码
(针对class文件装配探针)
-->
<target name="instrument" depends="init,compile">
<!--
Remove the 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}">
<!--
The 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 classes.
-->
<!-- 包含的类 -->
<include name="**/*.class" />
<!-- 排除的类 -->
<exclude name="**/*Test.class" />
</fileset>
</cobertura-instrument>
</target>
<!-- 单元测试 -->
<target name="test" depends="init,compile">
<junit fork="yes" dir="${basedir}">
<!--
Note the classpath order: instrumented 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 runtime, so Cobertura and its dependencies
must be on your classpath.
-->
<classpath refid="cobertura.classpath" />

<formatter type="xml" />
<test name="${testcase}" todir="${reports.xml.dir}" if="testcase" />
<batchtest todir="${reports.xml.dir}" unless="testcase">
<fileset dir="${test.dir}">
<include name="**/*Test.java" />
</fileset>
</batchtest>
</junit>

<junitreport 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" totallinerate="100" />
</target>-->
<!-- cobertura-report 任务生成覆盖率的 HTML 文件 -->
<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="summary-coverage-report">
<!--
Generate an summary XML file containing the coverage data using
the "srcdir" attribute.
-->
<cobertura-report srcdir="${src.dir}" destdir="${coverage.summaryxml.dir}" format="summaryXml" />
</target>

<!-- 生成cobertura HTML格式报告 -->
<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"/>
</fileset>
</cobertura-report>
</target>

<target name="clean" description="Remove all files created by the build/test process.">
<delete dir="${classes.dir}" />
<delete dir="${instrumented.dir}" />
<delete dir="${reports.dir}" />
<delete file="cobertura.log" />
<delete file="cobertura.ser" />
</target>
<!-- 默认运行,depends:指定target运行顺序 -->
<target name="coverage" depends="compile,instrument,test,coverage-report,summary-coverage-report,alternate-coverage-report" description="Compile, instrument ourself, run the tests and generate JUnit and coverage reports."/>

</project>

...全文
388 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
请叫我砖家 2013-11-12
  • 打赏
  • 举报
回复
帖子要沉掉么
请叫我砖家 2013-11-10
  • 打赏
  • 举报
回复
貌似一激动打错字了,见谅
静山晚风 2013-11-10
  • 打赏
  • 举报
回复
。。。这么长啊

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧