与Maven一起运行POM

时间:2017-04-13 15:31:31

标签: maven testng pom.xml

我正在通过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>

2 个答案:

答案 0 :(得分: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>

答案 1 :(得分:0)

对于要作为testng测试运行的东西,应该使用@Test注释进行注释。或者,如果以编程方式调用testng,则可以使用main方法创建套件programmatically

在你粘贴的代码中,只有一个main方法,这对于testng来说没什么意义。

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