如何在eclipse中使用ANT使用jcoverage java工具
我想使用ANT和eclipse为我的单元测试准备jcoverage报告。我正在使用 Apache AntTM版本1.8.3于2012年2月26日编译 selenium-server-standalone-2.20.0 junit-4.8.1.jar EclipseSDK3.6.1 我试过了,就像上面提到的 但我不能成功。请提供任何文件,或让我清楚如何准备报告 我的ant文件:如何在eclipse中使用ANT使用jcoverage java工具,eclipse,ant,automation,junit4,Eclipse,Ant,Automation,Junit4,我想使用ANT和eclipse为我的单元测试准备jcoverage报告。我正在使用 Apache AntTM版本1.8.3于2012年2月26日编译 selenium-server-standalone-2.20.0 junit-4.8.1.jar EclipseSDK3.6.1 我试过了,就像上面提到的 但我不能成功。请提供任何文件,或让我清楚如何准备报告 我的ant文件: <?xml version="1.0"?> <!DOCTYPE project [ <
<?xml version="1.0"?>
<!DOCTYPE project [
<!ENTITY start_stop_selenium SYSTEM "start_stop_selenium.xml">
<!ENTITY properties_build_clean_compile_report SYSTEM "properties_build_clean_compile_report.xml">
]>
<project name="Run Selenium Tests" default="all_selenium_tests" basedir=".">
<property name="libs" location="lib" />
<property name="build.dir" value="${basedir}/build/"/>
<property name="build.classes.dir" value="${build.dir}/classes"/>
<property name="build.test-classes.dir" value="${build.dir}/test-classes"/>
<property name="build.instrumented-classes.dir" value="${build.dir}/instrumented-classes"/>
<property name="build.coverage.dir" value="${build.dir}/coverage"/>
<property name="build.reports.dir" value="${build.dir}/reports"/>
<property name="lib.dir" value="lib"/>
<property name="src" value="src"/>
<property name="src.dir" value="${basedir}/src/java"/>
<property name="test.dir" value="${basedir}/src/test"/>
<!-- Corresponding Jar file for the Jcoverage.-->
<path id="jcoverage.path">
<fileset dir="${lib.dir}">
<include name="jcoverage-1.0.5.jar"/>
<include name="log4j-1.2.9.jar"/>
<include name="bcel-5.1.jar"/>
<include name="jakarta-oro-2.0.7.jar"/>
<include name="java-getopt-1.0.9.jar"/>
</fileset>
</path>
<path id="junit.class.path">
<fileset dir="${lib.dir}">
<include name="ant-junit.jar"/>
<include name="jcoverage-1.0.5.jar"/>
<include name="log4j-1.2.9.jar"/>
<include name="bcel-5.1.jar"/>
<include name="jakarta-oro-2.0.7.jar"/>
<include name="java-getopt-1.0.9.jar"/>
<include name="junit-4.8.1.jar"/>
<include name="selenium-server-standalone-2.20.0.jar"/>
<include name="jetty-repacked-7.6.1.jar"/>
<include name="org.mortbay.jetty-6.0.0alpha2.jar"/>
<include name="httpclient-4.1.2.jar"/>
<include name="httpcore-4.1.3.jar"/>
<include name="httpmime-4.1.2.jar"/>
<include name="selenium-java-2.20.0.jar"/>
<include name="selenium-java-2.20.0-srcs.jar"/>
<include name="logging-selenium-1.2.jar"/>
<include name="poi-3.7-20101029.jar"/>
<include name="robotframework-2.5.4.1.jar"/>
<include name="saxon-8.7.jar"/>
<include name="jxl.jar"/>
</fileset>
</path>
<target name="init">
<!-- <delete dir="${build.dir}"/>
<delete dir="${build.classes.dir}"/>
<delete dir="{build.test-classes.dir}"/>
<delete dir="${build.coverage.dir}"/>
<delete dir="${build.instrumented-classes.dir}"/>
<delete dir="${build.reports.dir}"/> -->
<delete dir="${build.dir}"/>
<mkdir dir="${build.dir}"/>
<mkdir dir="${build.classes.dir}"/>
<mkdir dir="${build.test-classes.dir}"/>
<mkdir dir="${build.coverage.dir}"/>
<mkdir dir="${build.instrumented-classes.dir}"/>
<mkdir dir="${build.reports.dir}"/>
</target>
<target name="compile" description="compile all classes">
<javac srcdir="${src.dir}" destdir="${build.classes.dir}" failonerror="yes" debug="yes">
</javac>
</target>
<target name="instrument" description="Add jcoverage instrumentation">
<instrument todir = "${build.instrumented-classes.dir}">
<ignore regex="org.apache.log4j.*"/>
<fileset dir="${build.classes.dir}">
<include name="**/*.class"/>
</fileset>
</instrument>
</target>
<target name="test" description="Unit test the application">
<javac srcdir="${test.dir}" destdir="${build.test-classes.dir}" failonerror="yes" debug="yes">
<classpath refid="junit.class.path"/>
<classpath location="${build.classes.dir}"/>
</javac>
<junit fork="yes" dir="${basedir}" errorProperty="test.failed" failureProperty="test.failed">
<!-- note the classpath order, instrumented classes are before the original (uninstrumented) classes. -->
<classpath refid="junit.class.path"/>
<classpath location="${build.instrumented-classes.dir}"/>
<classpath location="${build.classes.dir}"/>
<classpath location="${build.test-classes.dir}"/>
<!-- the instrumented classes reference classes used by the jcoverage runtime. -->
<classpath refid="jcoverage.path"/>
<formatter type="xml"/>
<batchtest todir="${build.reports.dir}" >
<fileset dir="${build.test-classes.dir}">
<include name="**/*Test.class"/>
</fileset>
</batchtest>
</junit>
</target>
<taskdef classpathref="jcoverage.path" resource="tasks.properties"/>
<target name="coverage" description="HTML and XML coverage reports can be found in build/coverage">
<report srcdir="${src.dir}" destdir="${build.coverage.dir}"/>
<report srcdir="${src.dir}" destdir="${build.coverage.dir}" format="xml"/>
<echo> jcoverage reports have been generated. The HTML report is ${build.coverage.dir}/index.html The XML report is ${build.coverage.dir}/coverage.xml </echo>
</target>
<target name="all_selenium_tests" description="The Main Target for running all tests">
<antcall target="init"/>
<antcall target="compile"/>
<antcall target="instrument"/>
<antcall target="test"/>
<antcall target="coverage"/>
</target>
</project>
控制台错误:
Buildfile: E:\jcoverage\jcoverage\refactored-param-build.xml
[taskdef] Could not load definitions from resource $(lib.dir). It could not be found.
all_selenium_tests:
[taskdef] Could not load definitions from resource $(lib.dir). It could not be found.
init:
[taskdef] Could not load definitions from resource $(lib.dir). It could not be found.
compiling:
[taskdef] Could not load definitions from resource $(lib.dir). It could not be found.
instrument:
BUILD FAILED
E:\jcoverage\jcoverage\refactored-param-build.xml:25: The following error occurred while executing this line:
E:\jcoverage\jcoverage\refactored-param-build.xml:96: Problem: failed to create task or type instrument
Cause: The name is undefined.
Action: Check the spelling.
Action: Check that any custom tasks/types have been declared.
Action: Check that any <presetdef>/<macrodef> declarations have taken place.
Total time: 125 milliseconds
请提供一个解决方案。错误通知您javac编译器找不到junit JAR。尽管您将junit.class.path指定为编译ant目标中的类路径,但该类路径包含对${libs}属性的引用,而该属性未在build.xml中定义 此外,在使用属性定义之前,您应该移动它们,如lib.dir,例如,在引用${lib.dir}的jcoverage.path的定义之前
注意:您可以看到使用-verbose选项调用ant或在任务之前调用${junit.class.path}任务所使用的类路径按照链接页面上的说明操作时遇到了什么问题?您好,Attila,我在这里添加了我的所有内容。请澄清。taskdef说找不到$lib.dir。您在taskdef中使用了错误的paranthesis。它必须是${lib.dir}@ores。我现在更改了所有这些内容,我得到了jcoverage报告。但它总是只显示0%的覆盖率,我无法运行我的单元测试。我在上面添加了我的ant文件和单元测试文件,这可能会帮助您澄清我的问题。感谢您的回复。我纠正了我的错误。现在我能够生成我的jcoverage报告。但是,它始终只显示0%的覆盖率。我的单元测试刚刚编译,但没有运行。请澄清一下。我认为问题是junit任务的元素引用了${src.dir}目录,它没有*.class文件。您提到的链接列出了${build.test classes.dir}。我也尝试过,但没有成功。报告只显示了0%的覆盖率。
Buildfile: E:\jcoverage\jcoverage\refactored-param-build.xml
[taskdef] Could not load definitions from resource $(lib.dir). It could not be found.
all_selenium_tests:
[taskdef] Could not load definitions from resource $(lib.dir). It could not be found.
init:
[taskdef] Could not load definitions from resource $(lib.dir). It could not be found.
compiling:
[taskdef] Could not load definitions from resource $(lib.dir). It could not be found.
instrument:
BUILD FAILED
E:\jcoverage\jcoverage\refactored-param-build.xml:25: The following error occurred while executing this line:
E:\jcoverage\jcoverage\refactored-param-build.xml:96: Problem: failed to create task or type instrument
Cause: The name is undefined.
Action: Check the spelling.
Action: Check that any custom tasks/types have been declared.
Action: Check that any <presetdef>/<macrodef> declarations have taken place.
Total time: 125 milliseconds