ant集成junit自动测试的build.xml标准模板
2006-07-26 21:08
585 查看
利用Ant集成Junit自动测试并生成测试报告,可以极大的提高测试的工作效率,其优势只要是测试用例的批量处理功能。前不久在网上看到很多关于Junit测试的文章,欣闻Ant支持Junit的集成,迫不及待的尝试了一番。
1. ant的配置:
本案例采用apache-ant-1.6.5版本,下载ant后需要将Junit3.8.1拷贝到ANT_HOME的lib目录下。Ant在执行过程TestCase过程中除了需要在classpath中可见,还需要在ant中可见,否则会报错。
2. 目录结构:
工作目录
|-src-|—com-|—wallace-|-Calculator.java
|-test-|-TestCalculator.java
|-lib-|-junit.jar
|-build
|-report
3. build.xml模板:
<?xml version="1.0" encoding="utf-8"?>
<project name="test" default="test" basedir=".">
<!--配置基本属性-->
<property name="src" value="src"/>
<property name="build" value="build"/>
<property name="lib" value="lib" />
<property name="dist" value="dist"/>
<property name="classpath" location="${build}"/>
<!--配置测试报告的属性-->
<property name="report" value="report"/>
<property name="report.xml" value="${report}/junit/xml"/>
<property name="report.html" value="${report}/junit/html"/>
<!--配置运行时classpath-->
<path id="classpath.run">
<pathelement path="${classpath}"/>
<fileset dir="${lib}">
<include name="*.jar"/>
</fileset>
</path>
<!--配置测试时classpath-->
<path id="classpath.test">
<path refid="classpath.run"/>
<path location="${dist}/lib/test-${DSTAMP}.jar"/>
</path>
<!--任务初始化-->
<target name="init" >
<tstamp/>
<delete dir="${build}"/>
<delete dir="${report}"/>
<delete dir="${dist}"/>
<mkdir dir="${build}"/>
</target>
<!--配置编译任务-->
<target name="compile" depends="init">
<javac srcdir="${src}" destdir="${build}">
<classpath refid="classpath.run" />
</javac>
</target>
<!--配置打包任务-->
<target name="dist" depends="compile">
<mkdir dir="${dist}/lib"/>
<jar jarfile="${dist}/lib/test-${DSTAMP}.jar" basedir="${build}"/>
</target>
<!--配置运行任务-->
<target name="run" depends="compile, dist">
<java classname="com.test.TestCalculator">
<classpath>
<path refid="classpath.run"/>
</classpath>
</java>
</target>
<!--配置JUnit测试,打印测试结果-->
<target name="test" depends="compile, dist">
<mkdir dir="${report.xml}"/>
<mkdir dir="${report.html}"/>
<junit printsummary="yes" haltonfailure="no">
<classpath refid="classpath.run"/>
<formatter type="xml"/>
<batchtest fork="yes" todir="${report.xml}">
<fileset dir="${src}" includes="**/Test*.java"/>
</batchtest>
</junit>
<junitreport todir="${report.html}">
<fileset dir="${report.
99f0
xml}">
<include name="*.xml"/>
</fileset>
<report format="frames" todir="${report.html}"/>
</junitreport>
</target>
</project>
1. ant的配置:
本案例采用apache-ant-1.6.5版本,下载ant后需要将Junit3.8.1拷贝到ANT_HOME的lib目录下。Ant在执行过程TestCase过程中除了需要在classpath中可见,还需要在ant中可见,否则会报错。
2. 目录结构:
工作目录
|-src-|—com-|—wallace-|-Calculator.java
|-test-|-TestCalculator.java
|-lib-|-junit.jar
|-build
|-report
3. build.xml模板:
<?xml version="1.0" encoding="utf-8"?>
<project name="test" default="test" basedir=".">
<!--配置基本属性-->
<property name="src" value="src"/>
<property name="build" value="build"/>
<property name="lib" value="lib" />
<property name="dist" value="dist"/>
<property name="classpath" location="${build}"/>
<!--配置测试报告的属性-->
<property name="report" value="report"/>
<property name="report.xml" value="${report}/junit/xml"/>
<property name="report.html" value="${report}/junit/html"/>
<!--配置运行时classpath-->
<path id="classpath.run">
<pathelement path="${classpath}"/>
<fileset dir="${lib}">
<include name="*.jar"/>
</fileset>
</path>
<!--配置测试时classpath-->
<path id="classpath.test">
<path refid="classpath.run"/>
<path location="${dist}/lib/test-${DSTAMP}.jar"/>
</path>
<!--任务初始化-->
<target name="init" >
<tstamp/>
<delete dir="${build}"/>
<delete dir="${report}"/>
<delete dir="${dist}"/>
<mkdir dir="${build}"/>
</target>
<!--配置编译任务-->
<target name="compile" depends="init">
<javac srcdir="${src}" destdir="${build}">
<classpath refid="classpath.run" />
</javac>
</target>
<!--配置打包任务-->
<target name="dist" depends="compile">
<mkdir dir="${dist}/lib"/>
<jar jarfile="${dist}/lib/test-${DSTAMP}.jar" basedir="${build}"/>
</target>
<!--配置运行任务-->
<target name="run" depends="compile, dist">
<java classname="com.test.TestCalculator">
<classpath>
<path refid="classpath.run"/>
</classpath>
</java>
</target>
<!--配置JUnit测试,打印测试结果-->
<target name="test" depends="compile, dist">
<mkdir dir="${report.xml}"/>
<mkdir dir="${report.html}"/>
<junit printsummary="yes" haltonfailure="no">
<classpath refid="classpath.run"/>
<formatter type="xml"/>
<batchtest fork="yes" todir="${report.xml}">
<fileset dir="${src}" includes="**/Test*.java"/>
</batchtest>
</junit>
<junitreport todir="${report.html}">
<fileset dir="${report.
99f0
xml}">
<include name="*.xml"/>
</fileset>
<report format="frames" todir="${report.html}"/>
</junitreport>
</target>
</project>
相关文章推荐
- 转: ant集成junit自动测试的build.xml标准模板
- ant集成junit自动测试的build.xml标准模板
- 用Ant自动测试JUnit(Ant测试自动化--上)
- 软件测试_JUnit+Ant构建自动的单元测试(1)
- ant+junit实现TDD,自动测试
- 软件测试_JUnit+Ant构建自动的单元测试(2)
- 使用Ant+JUnit+Cobertura来实现代码覆盖自动测试
- apacheAnt的构建脚本编写以及集成junit进行自动测试
- [jmeter]linux下自动测试环境+持续集成ant+jmeter+Apache(httpd)环境搭建与使用
- Ant 使用Junit自动测试要注意的问题
- 使用 Ant 集成 IBM Security AppScan Standard 进行自动测试
- ant结合junit进行软件自动测试
- ant+junit 自动生成测试报告
- ant结合junit进行软件自动测试(转)
- http://sourceforge.net/projects/easymock/ ant结合junit进行软件自动测试
- JUnit+ANT自动测试实验
- selenuim+testng集成ant和reportNG自动执行和发送测试报告
- 用Ant自动测试JUnit(Ant测试自动化--上)
- selenium进阶之基础--web自动测试框架(ant+junit+selenium)
- Jenkins集成JMeter性能测试与Ant构建性能测试