使用以下命令配置TestNG:org.apache.maven.surefire.testng.conf.TestNG652Configurator@2f410acf

时间:2018-08-29 06:37:17

标签: java maven testng

请提供有关如何在Maven中安装surefire插件的步骤。我用Google搜索,没有找到具体答案。关于该解决方案有很多答案,但是没有关于如何逐步安装插件的具体答案。

我得到的期望:

使用以下代码配置TestNG:org.apache.maven.surefire.testng.conf.TestNG652Configurator@2f410acf

我使用的pom.xml:

 <!-- language: xml --><?xml version="1.0" encoding="UTF-8"?>
<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>au.com.simcentric</groupId>
    <artifactId>Example20</artifactId>
    <version>1.0-SNAPSHOT</version>
     <packaging>jar</packaging>
    <dependencies>
        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>6.14.3</version>
            <type>jar</type>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-api</artifactId>
            <version>3.14.0</version>
            <type>jar</type>
        </dependency>
        <!-- https://mvnrepository.com/artifact/net.sourceforge.jexcelapi/jxl -->
<dependency>
    <groupId>net.sourceforge.jexcelapi</groupId>
    <artifactId>jxl</artifactId>
    <version>2.6.3</version>
</dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-remote-driver</artifactId>
            <version>3.14.0</version>
            <type>jar</type>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-chrome-driver</artifactId>
            <version>3.14.0</version>
            <scope>test</scope>
            <type>jar</type>
        </dependency>
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml</artifactId>
            <version>3.17</version>
            <type>jar</type>
        </dependency>

        <dependency>
   <groupId>org.jvnet.hudson.dom4j</groupId>
   <artifactId>dom4j</artifactId>
   <version>1.6.1-hudson-3</version>
</dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-support</artifactId>
            <version>3.14.0</version>
            <type>jar</type>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.hellojavaer/poi-excel-utils -->
<dependency>
    <groupId>org.hellojavaer</groupId>
    <artifactId>poi-excel-utils</artifactId>
    <version>1.0.0</version>
</dependency>
        <dependency>
            <groupId>com.sun.xml.bind</groupId>
            <artifactId>jaxb-xjc</artifactId>
            <version>2.1.13</version>
            <type>jar</type>
        </dependency>
        <dependency>
            <groupId>io.qameta.allure</groupId>
            <artifactId>allure-java-commons</artifactId>
            <version>2.0-BETA19</version>
            <type>jar</type>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <scope>test</scope>
            <version>2.44.0</version>
        </dependency>
        <dependency>
            <groupId>com.opera</groupId>
            <artifactId>operadriver</artifactId>
            <scope>test</scope>
            <version>1.5</version>
            <exclusions>
                <exclusion>
                    <groupId>org.seleniumhq.selenium</groupId>
                    <artifactId>selenium-remote-driver</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <scope>test</scope>
            <version>4.11</version>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-firefox-driver</artifactId>
            <version>3.14.0</version>
            <type>jar</type>
        </dependency>
</dependencies>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
         <vertx.version>3.0.0-milestone5</vertx.version>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>
    </project>

2 个答案:

答案 0 :(得分:0)

参考所附的pom.xml文件,很明显缺少surefire插件。 Maven需要知道要包括哪个插件以及哪个版本。建议以下内容:

在pom.xml文件中添加Maven Surefire插件条目

<build>
<pluginManagement>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-surefire-plugin</artifactId>
      <version>for example: 2.22.0</version>
    </plugin>
  </plugins>
</pluginManagement>

然后运行 MVN测试

上面的用法示例摘自here

再进一步,您还可以使用配置模式

包含/排除测试
<build>
<pluginManagement>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-surefire-plugin</artifactId>
      <version>for example: 2.22.0</version>
      <configuration>
        <includes>
          <include>IncludeTest.java</include>
        </includes>
        <excludes>
         <exclude>ExcludeTest.java</exclude>
        </excludes>
      </configuration>
    </plugin>
  </plugins>
</pluginManagement></build>

here显示了带有示例的详细说明。

如果您希望surefire挂接到您的testng.xml

       <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>${maven-surefire-plugin}</version>
            <configuration>
                <suiteXmlFiles>
                    <suiteXmlFile>testng.xml</suiteXmlFile>
                </suiteXmlFiles>
            </configuration>
        </plugin>

成功后,surefire插件将在项目文件夹内的目标/报告处生成XML报告。

答案 1 :(得分:0)

经过这么多研究人员,我找到了解决我问题的方法。首先,我认为pom.xml文件中存在问题。但是确保我的pom.xml是正确的后,我发现系统无法显示/识别我机器中的行家。 ( MVN测试)。 作为解决方案,我按照以下步骤进行操作,现在系统没有出现我在问题中提到的异常。

  1. 打开cmd并键入mvn test(在我的情况下,系统无法识别mvn)
  2. 导航至路径>编辑系统变量>环境变量>选择系统变量-路径 enter image description here

3。单击“编辑”按钮,然后将可用Maven的机器路径添加到可用路径的末尾。 enter image description here

4。单击确定

5.open cmd

6.type cmd测试<>

7。现在,您可以运行我的Maven项目,而我在我的问题中已经提到过:)