开发者

testNG taskdef definition in Ant using Maven dependencies

开发者 https://www.devze.com 2023-04-01 19:54 出处:网络
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:

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开发者_JAVA技巧.

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


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消