【问题标题】:testNG taskdef definition in Ant using Maven dependencies使用 Maven 依赖项在 Ant 中定义 testNG taskdef
【发布时间】:2011-11-07 23:07:23
【问题描述】:

我正在尝试使用 Ant 和 Maven 来构建一个项目。我正在使用 testNG 作为测试单元。如此处所述(http://testng.org/doc/ant.html)我已将 taskdef 定义如下:

<taskdef resource="testngtasks" classpath="testng.jar"/> 

在蚂蚁中。

在 Maven 中,我添加了以下内容(如此处所述:http://testng.org/doc/maven.html

<dependency>
  <groupId>org.testng</groupId>
  <artifactId>testng</artifactId>
  <version>6.2</version>
</dependency>

Maven 正在从 maven 存储库中获取文件,我检查了 /.m2 下的位置。现在我从 maven 获得了 testNG,我应该更改 ant 中的 taskdef 以在 Maven 存储库中使用这个新的。我不知道该怎么做。我尝试了以下方法:

<taskdef resource ="testngtasks" classname="org.testng" /> 

<taskdef resource ="testngtasks" classname="org.testng" classpathref="maven.compile.classpath"/>

<taskdef resource ="testngtasks" />

但没有成功,第二个抱怨我不应该使用 classpathref 而第一个说我应该指定类。第三个正在工作,但不完全。它正在进行中,我猜它通过了 taskdef 步骤,但它没有执行测试。蚂蚁的一部分(第三个):

<taskdef  resource="testngtasks"  />

<target name="test" depends="compile">
<echo message="running tests" />

Ant 输出的一部分:(注意 echo 执行了,它以某种方式通过了 taskdef 步骤)

compile:
    [javac] /home/shahin/Files/Development/Ant/ServiceEJBSample3/build-testNG.xml:31: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds

test:
     [echo] running tests

BUILD FAILED
/home/shahin/Files/Development/Ant/ServiceEJBSample3/build-testNG.xml:84: Problem: failed to create task or type testng
Cause: The name is undefined.
Action: Check the spelling.
Action: Check that any custom tasks/types have been declared.
Action: Check that any <presetdef>/<macrodef> declarations have taken place.

我不确定如何使用 Maven 存储库中的 testNG 库来定义( taskdef )Ant 中的 testngtasks。任何见解都将受到高度赞赏

【问题讨论】:

    标签: ant maven dependencies testng taskdef


    【解决方案1】:

    尝试为 taskdef 的类路径放置一个 pathelement 属性,例如:

    <taskdef resource="testngtasks">
         <classpath>
              <pathelement path="[path to]/testng.jar"/>
         </classpath>
    </taskdef>
    

    首先硬编码 pathelement 的路径以确保它适合您。

    【讨论】:

      【解决方案2】:

      我使用以下 taskdef 让它工作:

      <taskdef resource="testngtasks" classpath="./lib/testng-6.2.jar"/>
      

      当 Maven 检索 jar 时,它不会被命名为 testng.jar。因此,您需要将其重命名为适当的 jar 并更新 jar 的路径。

      【讨论】:

        猜你喜欢
        • 2014-08-10
        • 2014-05-25
        • 2012-10-25
        • 2017-07-31
        • 2016-02-17
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多