2011-08-31 86 views
0

我正尝试使用Ant和Maven构建项目。我正在使用testNG作为测试单元。如此处所述(http://testng.org/doc/ant.html)我已经定义了如下的taskdef:使用Maven依赖关系在Ant中测试N taskdef定义

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

in Ant。

在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" /> 

蚂蚁输出部分:(注意回声执行,它以某种方式通过的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中的测试用例。任何见解将高度赞赏

回答

0

试着将一个pathelement属性为您的taskdef像类路径:

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

第一硬编码为pathelement的路径,以确保它为你工作。

0

我得到它通过以下的taskdef工作:

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

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