maven-surefire-plugin:java.lang.NoSuchMethodError:org.testng.TestNG.configure(Ljava / util / Map;)V

时间:2015-07-26 16:28:44

标签: java maven selenium testing

我正在尝试使用“mvn clean test”命令对Java / TestNG执行测试。在pom中看起来有些不对劲,但我不知道是什么。

的pom.xml

ques_app_data

错误代码:

<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>Tests</groupId>
    <artifactId>GmailTest</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>


    <properties>
        <seleniumVersion>2.42.2</seleniumVersion>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

        <junit.version>4.8.2</junit.version>
   </properties>

    <repositories>
        <repository>
            <id>maven2.gueck.com-releases</id>
            <url>http://maven2.gueck.com/releases</url>
        </repository>
        <repository>
            <id>repo1</id>
            <url>http://repo1.maven.org/maven2</url>
        </repository>
        <repository>
            <id>repo2</id>
            <url>http://repo2.maven.org/maven2</url>

        </repository>
    </repositories>

    <dependencies>


        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-chrome-driver</artifactId>
            <version>${seleniumVersion}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-htmlunit-driver</artifactId>
            <version>${seleniumVersion}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.uncommons</groupId>
            <artifactId>reportng</artifactId>
            <version>1.1.2</version>
        </dependency>
       <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>6.9.4</version>
        </dependency>
        <dependency>
        <groupId>org.apache.maven.surefire</groupId>
        <artifactId>surefire-testng</artifactId>
        <version>2.18.1</version>
        </dependency>



    </dependencies>

 <build>
    <pluginManagement>
      <plugins>
        <plugin>
          <artifactId>maven-surefire-plugin</artifactId>
          <version>2.18.1</version>
           <configuration>
        <suiteXmlFiles>
          <suiteXmlFile>testng.xml</suiteXmlFile>
        </suiteXmlFiles>
      </configuration>
        </plugin>
      </plugins>
    </pluginManagement>
  </build>


</project>

我试图找到缺少的资源或存储库,没有任何运气。任何人都知道如何处理它?<​​/ p>

2 个答案:

答案 0 :(得分:2)

<pluginManagement>元素仅用于为<plugins>中引用的插件提供配置。 参见:Maven: What is pluginManagement?

您还缺少用于surefire插件的<groupId>

您的<build>元素应如下所示:

<build>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.18.1</version>
                <configuration>
                    <suiteXmlFiles>
                        <suiteXmlFile>testng.xml</suiteXmlFile>
                    </suiteXmlFiles>
                </configuration>
            </plugin>
        </plugins>
    </pluginManagement>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
        </plugin>
    </plugins>
</build>

答案 1 :(得分:0)

您需要添加surefire插件才能添加pom.XML