【问题标题】:Execute TestNG.xml file from Build.xml(ANT)从 Build.xml(ANT) 执行 TestNG.xml 文件
【发布时间】:2017-04-23 15:57:32
【问题描述】:

下面是我的 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>

【问题讨论】:

    标签: java xml apache ant testng


    【解决方案1】:

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-06-24
      • 2010-11-15
      • 2013-02-03
      • 2016-11-22
      • 1970-01-01
      • 2015-08-20
      • 2019-10-20
      • 1970-01-01
      相关资源
      最近更新 更多