2011-08-31 50 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。