利用ant进行自动化测试junit并生成报告

一、ant下载与安装
 进入https://ant.apache.org/  ,选择Binary Distributions 并选择bin.zip结尾的文件,下载安装并配置环境变量

二、build.xml文件的编写,例:

<?xml version="1.0"?>
<project name="Lab_1160300406" default="test auot junit and report" basedir=".">
    <!-- 定义工程依赖的jar包存放的位置 -->
 <property name="lib.dir" value="lib"/>
 <path id="classpath">
  <fileset dir="${lib.dir}" includes="**/*.jar"/>
 </path>
 <!-- 定义其他文件的位置 -->
 <property name="output folder" value="classes"/>
 <property name="src folder" value="src"/>
 <property name="test folder" value="test"/>
    <property name="report folder" value="report"/> 
 
    <target name="clean"> 
       <delete dir="report"/> 
       <echo>清除测试报告文件 成功!</echo> 
    </target> 
  
    <target name="compile init"> 
       <mkdir dir="${output folder}"/> 
       <echo>创建编译文件夹 成功!</echo> 
    </target> 
  
    <target name="report init" depends="clean"> 
       <mkdir dir="${report folder}"/> 
       <echo>创建测试报告文件夹 成功!</echo> 
    </target> 
  
    <target name="compile" depends="compile init"> 
       <javac srcdir="${src folder}" destdir="${output folder}" encoding="ISO-8859-1" classpathref="classpath" includeAntRuntime="false"/> 
       <echo>项目源文件编译 成功!</echo> 
    </target> 
  
    <target name="test compile" depends="report init"> 
       <javac srcdir="${test folder}" destdir="${output folder}" encoding="ISO-8859-1" classpathref="classpath" includeAntRuntime="false"/> 
       <echo>项目测试文件编译 成功!</echo> 
    </target> 
  
    <target name="all compile" depends="compile, test compile"> 
    </target> 
  
    <target name="test auot junit and report" depends="all compile"> 
       <junit printsummary="on" fork="true" showoutput="true"> 
           <classpath> 
              <fileset dir="${lib.dir}" includes="**/*.jar"/> 
              <pathelement path="${output folder}"/> 
           </classpath> 
           <formatter type="xml"/> 
           <batchtest todir="${report folder}"> 
              <fileset dir="${output folder}"> 
                  <include name="**/*Test.*"/> 
              </fileset> 
           </batchtest> 
       </junit> 
       <junitreport todir="${report folder}"> 
           <fileset dir="${report folder}"> 
              <include name="TEST-*.xml"/> 
           </fileset> 
           <report format="frames" todir="${report folder}"/> 
       </junitreport> 
    </target> 
     
</project> 

三、打开cmd,cd进入需要编译和运行的项目文件夹,键入 ant

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值