2017-04-13 193 views
0

我通過maven運行pom,出現以下錯誤。 Pom看起來沒問題。它在與testng一起運行時成功構建。有人可以幫我解決這個問題。與Maven一起運行POM


T E S T S 
------------------------------------------------------- 
Running TestSuite 

Results : 

Tests run: 0, Failures: 0, Errors: 0, Skipped: 0 

[INFO] ------------------------------------------------------------------------ 
[INFO] BUILD FAILURE 
[INFO] ------------------------------------------------------------------------ 
[INFO] Total time: 3.254 s 
[INFO] Finished at: 2017-04-13T15:56:01+01:00 
[INFO] Final Memory: 15M/222M 
[INFO] ------------------------------------------------------------------------ 
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.19.1:test (default-test) on project MavenTestNGpaytm: Execution default-test of goal org.apache.maven.plugins:maven-surefire-plugin:2.19.1:test failed: There was an error in the forked process 
[ERROR] java.lang.NoClassDefFoundError: org/testng/ITestListener 
[ERROR] at org.apache.maven.surefire.testng.TestNGXmlTestSuite.execute(TestNGXmlTestSuite.java:75) 
[ERROR] at org.apache.maven.surefire.testng.TestNGProvider.invoke(TestNGProvider.java:121) 
[ERROR] at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:290) 
[ERROR] at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:242) 
[ERROR] at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:121) 
[ERROR] Caused by: java.lang.ClassNotFoundException: org.testng.ITestListener 
[ERROR] at java.net.URLClassLoader.findClass(URLClassLoader.java:381) 
[ERROR] at java.lang.ClassLoader.loadClass(ClassLoader.java:424) 
[ERROR] at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331) 
[ERROR] at java.lang.ClassLoader.loadClass(ClassLoader.java:357) 
[ERROR] ... 5 more 
[ERROR] -> [Help 1] 
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. 
[ERROR] Re-run Maven using the -X switch to enable full debug logging. 
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles: 
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginExecutionException 

編輯

的testng.xml:

<?xml version="1.0" encoding="UTF-8"?> 

<suite name = "Automation Test"> 
    <test name = "Smoke Test"> 
     <classes> 
      <class name = "Premiums.Insurance"/> 
     </classes>  
    </test>  
</suite> 

的pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 
    <groupId>Insurance</groupId> 
    <artifactId>Premiums</artifactId> 
    <version>1</version> 
    <packaging>jar</packaging> 
    <name>Premiums</name> 
    <url>http://maven.apache.org</url> 
    <properties> 
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
    </properties> 
    <profiles> 
    <profile> 
     <id>Insurance</id> 
     <build> 
     <plugins> 
      <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-surefire-plugin</artifactId> 
      <version>2.19.1</version> 
      <configuration> 
       <suiteXmlFiles> 
       <suiteXmlFile>Insurance.xml</suiteXmlFile> 
       </suiteXmlFiles> 
      </configuration> 
      </plugin> 
     </plugins> 
     </build> 
    </profile> 
    </profiles> 
    <dependencies> 
    <dependency> 
     <groupId>org.seleniumhq.selenium</groupId> 
     <artifactId>selenium-java</artifactId> 
     <version>3.3.1</version> 
    </dependency> 
    <dependency> 
     <groupId>io.appium</groupId> 
     <artifactId>java-client</artifactId> 
     <version>2.1.0</version> 
    </dependency> 
    <dependency> 
     <groupId>org.testng</groupId> 
     <artifactId>testng</artifactId> 
     <version>6.7</version> 
    </dependency> 
    </dependencies> 
</project> 
+0

你可以分享你的代碼testng.xml&pom.xml嗎? – DebanjanB

+0

6.7是一款非常古老的TestNG版本。可以再試一次更新的版本,並告訴我們它是否工作? – juherr

+0

請不要創建答案將信息添加到您的問題。答案應該只包含你的問題的答案。如果你想對你的問題進行補充/修改,那麼你可以編輯它。 – Makyen

回答

0

你必須使用這些依賴關係和插件。

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

<build> 
    <plugins> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-compiler-plugin</artifactId> 
      <configuration> 
       <source>1.8</source> 
       <target>1.8</target> 
      </configuration> 
     </plugin> 
    </plugins> 
</build> 
0

對於一些作爲一個TestNG的試運行,它應該@Test註釋來註釋。或者,如果您以編程方式調用testng,則可以使用主方法創建套件programmatically

在你粘貼的代碼中,只有一個主要的方法,這對testng沒有任何意義。

添加testng註釋,重新命名方法以發出更多測試,並閱讀一些基本知識here

+0

我已添加@test註釋。它運行時,我執行mvn測試和成功構建,但失敗時,我做了mvn測試 - 派生與錯誤'有一個錯誤的叉進程'。 – Tessy

+0

我已經粘貼上面的當前錯誤。如果有人能爲此提供幫助,我將不勝感激。謝謝 – Tessy