testNG taskdef definition in Ant using Maven dependencies

◇◆丶佛笑我妖孽 提交于 2019-12-11 18:17:08

问题


I am trying to use Ant and Maven to build a project. I am using testNG for test units. As stated here ( http://testng.org/doc/ant.html ) I have defined the taskdef as follow:

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

in Ant.

In Maven I have added the following (as stated here: http://testng.org/doc/maven.html)

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

Maven is getting the files from maven repository and I have checked the location under /.m2. Now that I am getting the testNG from maven, I should change the taskdef in ant to use this new one in Maven repository. I am not sure how to do that. I have tried the following:

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

and

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

and

<taskdef resource ="testngtasks" />

but no success, the second one complains that I shouldn't use classpathref and the first one says that I should specify class. The third one is working kind of, but not completely. It is going thorugh and I guess it passes the taskdef step but it is not executing the tests. Part of the Ant (for third one):

<taskdef  resource="testngtasks"  />

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

Part of the Ant output: (note that the echo executed, it is somehow passed the taskdef step)

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.

I am not sure how to use testNG library in Maven repository to define ( taskdef ) the testngtasks in Ant. Any insights would be highly appreciated


回答1:


try placing a pathelement property in for the classpath of your taskdef like:

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

first hardcode the path for pathelement to make sure it's working for you.




回答2:


I got it to work by using the following taskdef:

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

When Maven retrieves the jar it will not be named testng.jar. So you will need to rename it to the appropriate jar and update the path to jar.



来源:https://stackoverflow.com/questions/7263301/testng-taskdef-definition-in-ant-using-maven-dependencies

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!