ant 结合junit 增量开发

1.将 junit.jar 放在 ANT_HOME\lib 目录下 
2.修改 build.xml ,加入如下 内容: 以下是我自己的:

<?xml version="1.0" encoding="UTF-8"?>
<!-- ====================================================================== 
     2009-2-27 下午02:26:07                                                        

     TestAnt2Junit    
     description
                   
     Administrator                                                                
     ====================================================================== -->
<project name="TestAnt2Junit" default="junit">
    <description>
            测试ant junit 增量开发
    </description>
	<property name="run.calsspath" value="bin"/>
	<property name="run.srcpath" value="src"/>
	<property name="test.srcpath" value="src"/>
	<property name="test.report" value="report"/>
	<property name="lib.dir" value="lib"/>
	<path id="compile.path">
		<fileset dir="${lib.dir}">
			<include name="**/*.jar"/>
		</fileset>
	</path>
	
	
	  

    <!-- ================================= 
          target: junit              
         ================================= -->
    <target name="junit" depends="compile" description="单元测试">
     <tstamp></tstamp>
	<mkdir dir="${test.report}"/>
	<mkdir dir="${test.report}/framework-${DSTAMP}-${TSTAMP}"/>
	<junit printsummary="true">
	<classpath>
	<pathelement path="${run.calsspath}"/>
	  <fileset dir="${lib.dir}">
		<include name="**/*.jar"/>
	  </fileset>
	</classpath>
	<formatter type="plain"/>
	<batchtest fork="yes" todir="${test.report}/framework-${DSTAMP}-${TSTAMP}">
	<fileset  dir ="${test.srcpath}" > 
    <include  name ="**/*Test.java"   /> 
	</fileset > 
    </batchtest > 
	</junit > 
    </target>
	
	 <!-- ================================= 
	          target: compile              
	         ================================= -->
	<target name="compile" description="编译">
	<javac destdir="${run.calsspath}" srcdir="${run.srcpath}" classpathref="compile.path"/>
	<javac destdir="${run.calsspath}" srcdir="${test.srcpath}" classpathref="compile.path"/>
	</target>

   

</project>

 

ant 提供了两个 target : junit 和 junitreport  
运行所有 测试用例 ,并生成 html 格式的报表

下面是别人的:

    <property name="report" value="report" />  

    <target name="junitreport" depends="clean, compile">  
        <junit printsummary="on"  
                fork="true"  
                haltonfailure="false"  
                failureproperty="tests.failed"  
                showoutput="true">  
            <classpath refid="myclasspath"/>  
            <formatter type="xml"/>  
            <batchtest todir="${report}">  
                <fileset dir="${build}">  
                    <include name="**/*Test.*"/>  
                </fileset>  
            </batchtest>  
        </junit>  
        <junitreport todir="${report}">  
            <fileset dir="${report}">  
                <include name="TEST-*.xml"/>  
            </fileset>  
            <report format="frames" todir="${report}"/>  
        </junitreport>  
        <fail if="tests.failed">  
            ---------------------------------------------------------  
            One or more tests failed, check the report for detail...  
            ---------------------------------------------------------  
        </fail>  
    </target>  

 

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值