Eclipse环境下 从Ant 中执行Junit测试
在工程下新建build.xml(附件里提供了源代码的下载)
关于JUnitReport的打印问题:
【Windows-Preference-Ant-Runtime-Ant Home Entries】
窗口—首选项—ant—运行时—类路径—Ant主目录条目,然后添加外部jar。 主要添加junit.jar这个文件即可。 实际不需要optional.jar这个文件。
[img]http://www.iteye.com/upload/attachment/29424/53cb6c12-71ae-3b69-8f07-af6cf53a031d.jpg[/img]
(因为,org.apache.ant_1.6.2\lib\ant-junit.jar这个文件,就是一个Ant中JUnit任务可选项的扩展.jar文件,现在缺的只是ANT可以找到的JUnit的jar文件。
Ant类似于SpringFramework,它托管管理了JUnit,但是实际功能还是委派给JUnit.jar来实现的!)
在工程下新建build.xml(附件里提供了源代码的下载)
<?xml version="1.0"?>
<project name="kker" default="compile">
<property file="build.properties"></property>
<!--领域对象目录-->
<property name="java.dir" location="java"></property>
<!--测试对象目录-->
<property name="test.dir" location="test"></property>
<!--class文件目录-->
<property name="target.dir" location="target"></property>
<!--打印报告文件目录-->
<property name="target.report.dir" location="${target.dir}/report"></property>
<!--class文件目录-->
<property name="target.classes.java.dir" location="${target.dir}/classes/java"></property>
<!--class文件目录-->
<property name="target.classes.test.dir" location="${target.dir}/classes/test"></property>
<!--编译领域对象-->
<target name="compile.java">
<mkdir dir="${target.classes.java.dir}"/>
<javac destdir="${target.classes.java.dir}">
<src path="${java.dir}"></src>
</javac>
</target>
<!--编译测试对象-->
<target name="compile.test" depends="compile.java">
<mkdir dir="${target.classes.test.dir}"/>
<javac destdir="${target.classes.test.dir}">
<src path="${test.dir}"/>
<!--关联的领域对象-->
<classpath>
<pathelement location="${target.classes.java.dir}"/>
</classpath>
</javac>
</target>
<!--编译领域对象和测试对象-->
<target name="compile" depends="compile.java,compile.test"></target>
<!--测试-->
<target name="test" depends="compile">
<mkdir dir="${target.report.dir}"/>
<property name="tests" value="Test*"/>
<!--printsummary="yes" : 在测试的最后一行生成一个单行的概要-->
<!--haltonerror="yes" haltonfailure="yes" :如果失败或产生错误将停止编译-->
<!--fork="yes" :每个测试分别使用一个单独的java虚拟机(JUM)-->
<junit printsummary="yes" haltonerror="yes" haltonfailure="yes" fork="yes">
<formatter type="plain" usefile="false"/>
<formatter type="xml"/>
<!--自动找出要运行的测试-->
<batchtest todir="${target.report.dir}">
<fileset dir="${test.dir}">
<include name="**/${tests}.java"/>
<include name="**/Test*All.java"/>
</fileset>
</batchtest>
<!--为本次任务添加你刚刚编译的类-->
<classpath>
<pathelement location="${target.classes.java.dir}"/>
<pathelement location="${target.classes.test.dir}"/>
</classpath>
</junit>
</target>
<!--打印报告-->
<target name="report" depends="test">
<mkdir dir="${target.report.dir}/html"/>
<!--调用junitreport来产生报告-->
<junitreport todir="${target.report.dir}">
<fileset dir="${target.report.dir}">
<include name="TEST-*.xml"/>
</fileset>
<report todir="${target.report.dir}/html"/>
</junitreport>
</target>
</project>
关于JUnitReport的打印问题:
【Windows-Preference-Ant-Runtime-Ant Home Entries】
窗口—首选项—ant—运行时—类路径—Ant主目录条目,然后添加外部jar。 主要添加junit.jar这个文件即可。 实际不需要optional.jar这个文件。
[img]http://www.iteye.com/upload/attachment/29424/53cb6c12-71ae-3b69-8f07-af6cf53a031d.jpg[/img]
(因为,org.apache.ant_1.6.2\lib\ant-junit.jar这个文件,就是一个Ant中JUnit任务可选项的扩展.jar文件,现在缺的只是ANT可以找到的JUnit的jar文件。
Ant类似于SpringFramework,它托管管理了JUnit,但是实际功能还是委派给JUnit.jar来实现的!)