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 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