Ant典型实例一览

一 : Ant和junit实现自动化测试

       1: junit和ant的整合: 使用ant实现junit测试,并且生成测试报告
       
             <?xml version="1.0" encoding="UTF-8"?>
             <project name="junit-test">
            <!--以下是我们自定义的属性,实际开发中常用到,推荐我们使用属性-->
        <property name="src.dir" location="src"></property>
        <property name="test.src.dir" location="test"></property>
        <property name="lib.dir" location="lib"></property>
        <property name="build.dir" location="build"></property>
        <property name="build.classes" location="${build.dir}/classes"></property>
        <property name="build.test.dir" location="${build.dir}/test"></property>
        <property name="build.test.classes" location="${build.test.dir}/classes"></property>
        <property name="build.test.report" location="${build.test.dir}/report"></property>
        <property name="run.test.class" value="**/Test*.class"></property>
        
        <!--以下是路径的定义,比如我们的某些目标操作需要的依赖,包括依赖jar和依赖的类,
        大量的依赖我们可以使用文件集合,path属性或者子元素可以递归的解析指定的路径
        或者引用其他的path,pathelement可以单独的指定所需资源的路径
        总的来说就是: “我们执行什么操作,需要什么,需要的资源就用path来指定”-->
        <path id="compile-path">
            <fileset dir="${lib.dir}" includes="*.jar"></fileset>
        </path>
        <path id="compile-test-path">
            <path refid="compile-path"></path>
            <pathelement location="${build.classes}"/>
        </path>
        <path id="run-test-path">
            <path refid="compile-test-path"></path>
            <pathelement location="${build.test.classes}"/>
        </path>



                <!--执行操作之前先进行清理工作-->
        <target name="clean">
            <echo>进行项目的清理工作</echo>
            <delete dir="${build.dir}"></delete>
        </target>
        
        <target name="init">
            <echo>进行项目的初始化</echo>
            <mkdir dir="${build.dir}"/>
            <mkdir dir="${build.classes}"/>
            <mkdir dir="${build.test.dir}"/>
            <mkdir dir="${build.test.classes}"/>
            <mkdir dir="${build.test.report}"/>
        </target>
        
        <!--编译源代码-->
        <target name="compile" depends="init">
            <echo>编译源文件</echo>
            <javac failοnerrοr="true" includeantruntime="true" srcdir="${src.dir}" destdir="${build.classes}" classpathref="compile-path"></javac>
        </target>
        
            <!--编译测试源代码-->
        <target name="compile-test" depends="compile">
            <echo>编译测试文件</echo>
            <javac failοnerrοr="true" includeantruntime="true" srcdir="${test.src.dir}" destdir="${build.test.classes}" classpathref="compile-test-path"/>
        </target>
        

        <!--进行单元测试-->
        <target name="run-test" depends="compile-test">
            <echo>运行单元测试</echo>
            <!--以下printsummary属性表示的是测试是否输出简要信息,haltonfailure表示的是
            一旦我们这个测试发生失败是否继续执行后面的操作,batchtest指的是批量测试,我们
            一次可以执行多个测试,todir属性表示我们测试报告的输出路径,formatter元素表示的是
            测试报告的输出格式是什么-->
            <junit printsummary="false" haltonfailure="false">
                <classpath refid="run-test-path"></classpath>
                <formatter type="brief" usefile="false"/>
                <!--<test name="${run.test.class}"></test>-->
                <formatter type="xml"/>
                <batchtest todir="${build.test.report}">
                    <fileset dir="${build.test.classes}" includes="${run.test.class}"></fileset>
                </batchtest>
            </junit>

            <!--junitreport的功能是将junit测试生成的xml文件创建为格式良好的测试报告,
            todir表示的是junit测试生成的xml文件的路径,fileset是去选择生成测试报告的源xml
            文件,report子元素指定了按照指定的格式生成格式良好的测试报告,todir指定了
            测试报告的生成目录-->
            <junitreport todir="${build.test.report}">
                <fileset dir="${build.test.report}" includes="TEST-*.xml"></fileset>
                <report format="frames" todir="${build.test.report}/html"/>
            </junitreport>
        </target>
        
        <target name="end" depends="run-test">
            <echo>整个过程结束</echo>
        </target>
       </project>


二:  生成一个java API doc并且将我们所需资源打包:
         
     <project name="ant_zip_doc">

        <property name="src.dir" location="src"></property>
        <property name="build.dir" location="build"></property>
        <property name="build.classes" location="${build.dir}/classes"></property>
        <property name="build.doc" location="
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值