2017-04-13 169 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