ant testng 问题

1.build.xml:31: No suites, classes, methods or jar file was specified

问题解决:

         <xmlfileset dir="${basedir}" includes="TestNG001.xml"/> 

此段中的testng.xml文件路径配置错误或者文件名错误,找到testng.xml正确的路径或者名称重新配置即可;


2.编译警告
    [javac]build.xml:12: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds

解决方法:

在<javac debug="true" classpathref="cpath" srcdir="src/test/java/test/haha"  destdir="classes"/> 中加入

  includeantruntime="on"即可,如下所示:

<javac debug="true" classpathref="cpath" srcdir="src/test/java/test/haha" destdir="classes" includeantruntime="on"/>

3.testng.xml文件不执行

以下为在练习ant + testNG过程中,碰到了但还未找到原因,先记下来,等以后再研究

测试java源代码内容为:

package Ant;
import org.testng.annotations.*;
public class AntTest{
@Test(groups = {"t1"} )
      public static void frist(){
           for(int i=0;i<=10;i++){
                 System.out.println(i);
           }
      }
@Test(groups = {"t3"} )
    public static void scen(){
               System.out.println("wo shi di san");
    }
}

其中build.xml文件如下:

<?xml version="1.0" encoding="UTF-8" ?>
<project name="HelloWorld" default="regression" basedir=".">
<property name="src" value="src"/>
<property name="dest" value="classes"/>
<property name="testng.dir"  value="E:\Users\Administrator\workspace\TestAnt\lib"/>
<property name="testng.output.dir" value="E:\Users\Administrator\workspace\TestAnt\test-output"/>


 <path id="class1">
        <fileset dir="E:\Users\Administrator\workspace\TestAnt" includes="*jar"/>
        <fileset dir="E:\Users\Administrator\workspace\TestAnt" includes="*zip"/>
<fileset dir="E:\Users\Administrator\workspace\TestAnt" includes="*class"/>

<fileset dir="E:\Users\Administrator\workspace\TestAnt\lib" includes="*jar"/>
        <pathelement location="${dest}"/>
<pathelement location="${src}"/>
 </path>

<taskdef resource="testngtasks" classpath="${testng.dir}/testng.jar"/>

<target name="init">
<delete dir="${dest}"/>
   <mkdir dir="${dest}"/>
   <mkdir dir="dist"/>
</target>
<target name="compile" depends="init">
   <javac srcdir="${src}" destdir="${dest}"  classpathref="class1" includeantruntime="off" debug="on" debuglevel="lines,vars,source"/>
</target>

 <target name="regression" depends="compile">
<echo>running testng</echo>
        <testng outputdir="${testng.output.dir}" classpathref="class1" delegateCommandSystemProperties="true">
            <xmlfileset dir="E:\Users\Administrator\workspace\TestAnt" includes="testng.xml"/>
        </testng>
 </target>
</project>

testng.xml文件内容如下:

<?xml version="1.0" encoding="UTF-8"?>
<suite name="Suite" parallel="false">
  <test name="Test"   preserve-order="true"> 
    <classes>
    <class name="Ant.AntTest"/>
    </classes> 
  </test> <!-- Test -->
</suite> <!-- Suite -->

build.xml文件如上所示时,执行ant结果为:

Buildfile: E:\Users\Administrator\workspace\TestAnt\build.xml
init:
   [delete] Deleting directory E:\Users\Administrator\workspace\TestAnt\classes
    [mkdir] Created dir: E:\Users\Administrator\workspace\TestAnt\classes
compile:
    [javac] Compiling 1 source file to E:\Users\Administrator\workspace\TestAnt\classes
regression:
     [echo] running testng
   [testng] [TestNG] Running:
   [testng]   E:\Users\Administrator\workspace\TestAnt\testng.xml
   [testng] ===============================================
   [testng] Suite
   [testng] Total tests run: 0, Failures: 0, Skips: 0
   [testng] ===============================================
BUILD SUCCESSFUL
Total time: 6 seconds

可以看到没有执行,如上红色所示,当把build.xml文件中紫色部分去除后,再次运行,即可得正确结果,执行结果如下:

Buildfile: E:\Users\Administrator\workspace\TestAnt\build.xml
init:
   [delete] Deleting directory E:\Users\Administrator\workspace\TestAnt\classes
    [mkdir] Created dir: E:\Users\Administrator\workspace\TestAnt\classes
compile:
    [javac] Compiling 1 source file to E:\Users\Administrator\workspace\TestAnt\classes
regression:
     [echo] running testng
   [testng] [TestNG] Running:
   [testng]   E:\Users\Administrator\workspace\TestAnt\testng.xml
   [testng] 0
   [testng] 1
   [testng] 2
   [testng] 3
   [testng] 4
   [testng] 5
   [testng] 6
   [testng] 7
   [testng] 8
   [testng] 9
   [testng] 10
   [testng] wo shi di san
   [testng] ===============================================
   [testng] Suite
   [testng] Total tests run: 2, Failures: 0, Skips: 0
   [testng] ===============================================
BUILD SUCCESSFUL
Total time: 6 seconds

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值