2015-11-19 147 views
1

我正在使用linux mechine(ubuntu 14)。我的項目是與testng框架工作的maven項目。這裏我試圖從命令提示符運行testng.xml,以便我可以在jenkins中進行配置。如何從命令提示符下運行maven項目testng.xml

project location : /home/subhash/workspace/myproject 
class path is : /home/subhash/workspace/myproject/bin 
testng jar locattion is: /home/subhash/.m2/repository/org/testng/testng/6.9.4/testng-6.9.4.jar" 

suite location is : /home/subhash/workspace/suites/src/test/resources/testng.xml 

hence i executed the following command from command prompt from the location. 
/home/subhash/workspace/myproject/bin$ 

$ java -cp ".:../lib/*:/home/subhash/.m2/repository/org/testng/testng/6.9.4/testng-6.9.4.jar" org.testng.TestNG /home/subhash/workspace/suites/src/test/resources/testng.xml 

我得到以下例外:

Exception in thread "main" java.lang.NoClassDefFoundError: com/beust/jcommander/ParameterException

因此,我已經添加在pom.xml中的依賴關係如下。

<dependency> 
<groupId>com.beust</groupId> 
<artifactId>jcommander</artifactId> 
<version>1.48</version> 

構建它。它是成功的。 我再次運行上面提到的命令來運行testng.xml,但仍顯示相同的異常。

請幫我解決這個問題。

在此先感謝。 Subhash。

回答

0

看看這個問題:Suddenly can't run TestNG tests from ant ([testng] Caused by: java.lang.ClassNotFoundException: com.beust.jcommander.ParameterException)

這似乎是同樣的問題

希望幫助!

UPDATE

嘗試添加到CP的Java參數裏的 '博伊斯特' 罐子路徑平方米。

+0

嗨,Francis,感謝您的回覆。正如我在文章中所建議的那樣,我已經完成了。我用最新版本替換了我的testng.jar文件,並嘗試再次運行testng.xml文件,但仍然顯示Exception異常。異常在線程「main」java.lang.NoClassDefFoundError:com/beust/jcommander/ParameterException \t at java.lang.Class.getDeclaredMethods0(Native Method) – subhash

+0

嗨Subash,你嘗試添加到-cp java參數的' beust'jar路徑?以與添加testng jar路徑相同的方式執行此操作 –

0

使用mvn測試而不是testng jar運行測試會更容易。 在pom中設置mvn surefire插件並使用mvn test -DsuiteXmlFile = src/test/resources/yourxml.xml運行

+0

我嘗試添加此插件並運行maven測試。異常顯示。未能執行目標org.apache.maven.plugins:maven-surefire-plugin:2.19:test-suite上的測試(默認測試):目標的執行默認測試org.apache.maven.plugins:maven -surefire-plugin:2.19:測試失敗:分叉進程中出現錯誤 [錯誤] org.apache.maven.surefire.testset.TestSetFailedException:Suite文件/home/subhash/workspace/test-suite/test_suite_main.xml不是有效的文件 [錯誤]在org.apache.maven.surefire.testng.TestNGXmlTestSuite.locateTestSets(TestNGXmlTestSuite.java:115) – subhash

+0

它說套件文件無效。這個路徑是否可以從你的Maven運行的地方訪問? –

+0

只需將該文件放在您的項目中,並使用src/test/resources/testng.xml ..無需給絕對路徑 –

相關問題