从Build.xml(ANT)执行TestNG.xml文件

时间:2017-04-23 15:57:32

标签: java xml apache ant testng

下面是我的Build.xml文件。我试图通过Build.xml执行我的TestNG.xml,但每次都会收到以下错误。

[testng]在类路径中找不到类:

以下文件在编译目标之前正常工作。我想用 exec 目标编写的代码存在一些问题。

如果我单独尝试执行我的TestNG.xml文件,它的工作完全正常。没有问题。但是当我从Build.xml执行我的TestNG.xml时会出现问题。

我已经尝试通过我在stackoverflow上找到的一些方法来解决这个问题,例如:

  • 清洁项目
  • 更新TestNG库 但它没有成功。

有人可以帮我吗?

    

<property name="lib" value="./lib" />

<property name="bin" value="./bin" />

<path id="Sample Ant build.classpath">
    <pathelement location="${output}" />
    <fileset dir="${lib}">
        <include name="**/*.jar" />
    </fileset>
</path>

<target name="init">
    <delete dir="${bin}">
    </delete>
    <mkdir dir="${bin}" />
</target>

<target name="compile" depends="init">
    <javac srcdir="${src}" 
         destdir="${bin}"
        includeantruntime="false"   
         debug="true">
        <classpath refid="Sample Ant build.classpath"/>
    </javac>
</target>

<!-- Runs the file and generates Reportng report for TestNG-->
<taskdef name="testng" classname="org.testng.TestNGAntTask" classpathref="Sample Ant build.classpath" />

<target name="exec" depends="compile">
    <mkdir dir="${testng_report_dir}" />
    <testng outputdir="${testng_report_dir}" classpathref="Sample Ant build.classpath" useDefaultListeners="true">
        <xmlfileset dir="${basedir}" includes="Testng.xml" />
    </testng>

</target>

1 个答案:

答案 0 :(得分:0)

问题出在我在build.xml中设置的类路径中。下面是正确的类路径。

<path id="classpath">
    <pathelement location="${bin}" />
    <fileset dir="${lib}">
        <include name="**/*.jar" />
    </fileset>
</path>

$ {bin}是编译.java文件后.class文件所在的目录。

相关问题