【问题标题】:running POM with Maven使用 Maven 运行 POM
【发布时间】:2017-04-13 15:31:30
【问题描述】:

我正在通过 maven 运行 pom,并收到以下错误。 Pom 看起来不错。使用 testng 运行时成功构建。有人可以帮我解决这个问题。


 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>

【问题讨论】:

  • 你能分享你的代码,testng.xml & pom.xml 吗?
  • 6.7 是一个非常古老的 TestNG 版本。是否可以使用更新的版本再试一次并告诉我们它是否正常工作?
  • 请不要创建答案来为您的问题添加信息。答案应该只包含您的问题的答案。如果您想对您的问题进行添加/更改,那么您可以edit它。

标签: maven testng pom.xml


【解决方案1】:

你必须使用这些依赖和插件。

<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>

【讨论】:

    【解决方案2】:

    对于作为 testng 测试运行的东西,它应该使用 @Test 注释进行注释。或者,如果您以编程方式调用 testng,那么您可以有一个 main 方法,您可以在其中创建一个套件 programmatically

    在您粘贴的代码中,只有一个 main 方法,这对 testng 没有任何意义。

    添加 testng 注释,重命名方法听起来更像测试,并阅读一些基础知识here

    【讨论】:

    • 我已经添加了@test 注释。它在我执行 mvn test 并成功构建时运行,但在我执行 mvn test -PInsuance 时失败,并出现错误“Fork 过程中出现错误”。
    • 我已经粘贴了上面的当前错误。如果有人可以提供帮助,我将不胜感激。谢谢
    猜你喜欢
    • 1970-01-01
    • 2012-02-09
    • 1970-01-01
    • 1970-01-01
    • 2012-09-23
    • 1970-01-01
    • 2011-02-18
    • 2011-05-30
    • 2017-04-10
    相关资源
    最近更新 更多