敏捷开发学习之二_ant

注意:利用ant运行测试程序。

<? xml version="1.0" ?>

< project  name ="agileJava"  default ="rebuildAll"  basedir ="." >
    
< property  name ="src.dir"  value ="${basedir}"   />
    
< property  name ="build.dir"  value ="${basedir}classes"   />
    
< property  name ="report.xml"  value ="${basedir}/junit/xml"   />
    
< property  name ="report.html"  value ="${basedir}/junit/html"   />
    
    
< path  id ="classpath" >
        
< fileset  dir ="${src.dir}" >
            
< include  name ="*.jar"   />
        
</ fileset >
        
< pathelement  path ="${build.dir}"   />
    
</ path >
    
    
< target  name ="init" >
        
< mkdir  dir ="${build.dir}"   />
        
< mkdir  dir ="${report.xml}"   />
        
< mkdir  dir ="${report.html}" />
    
</ target >

    
< target  name ="build"  depends ="init"  description ="build all" >
        
< javac  srcdir ="${src.dir}"  destdir ="${build.dir}"  source ="1.5"  deprecation ="on"  debug ="on"  optimize ="off"  includes ="**" >
            
< classpath  refid ="classpath"   />
        
</ javac >
    
</ target >
<!--   运行测试用例,并生成xml -->
    
< target  name ="junitgui"  depends ="build"  description ="run junitgui" >
    
< junit  printsummary ="yes"  haltonfailure ="no" >
            
< classpath  refid ="classpath"   />
            
< formatter  type ="xml"   />
            
< batchtest  fork ="yes"  todir ="${report.xml}" >
                
< fileset  dir ="${build.dir}"  includes ="**/AllTests.class"   />
            
</ batchtest >
        
</ junit >
    
</ target >
    
<!--   由生成的xml,生成html -->
    
< target  name ="report"  depends ="junitgui" >
        
< junitreport  todir ="${report.html}" >
            
< fileset  dir ="${report.xml}" >
                
< include  name ="TEST-*.xml" />
            
</ fileset >
            
< report  todir ="${report.html}" />
        
</ junitreport >
    
</ target >
    
< target  name ="clean" >
        
< delete  dir ="${build.dir}"   />
        
< delete  dir ="${report.xml}"   />
        
< delete  dir ="${report.html}" />
    
</ target >

    
< target  name ="rebuildAll"  depends ="clean,build,junitgui,report"  description ="rebuild all"   />
</ project >

由于前面的测试用例,是采用的junit4的标注。如果
在ant中使用junit4还是有点问题。因为ant1.6.5等以前的版本不支持junit4。
必须去下载ant1.7.下载http://ant.apache.org/bindownload.cgi 

 如果出现错误:

ould not create task or type of type: junit.
Ant could not find the task or a class this task relies upon.

那:

 you need to go into Eclipse then click on Window->Preferences->ant->Runtime,
then select 'Ant Home Entries (Default). Click on the button 'Add External JARs'.
Locate the junit.jar file you copied, select it and hit 'OK'. Hit 'Apply',
then 'OK' and try your ant task again. That should fix it.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值