【问题标题】:Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:3.0.0-M5:test (default-test) on project未能在项目上执行目标 org.apache.maven.plugins:maven-surefire-plugin:3.0.0-M5:test (default-test)
【发布时间】:2021-06-28 19:14:37
【问题描述】:

我正在使用 JAVA、MAVEN 和 TESTNG 组合进行测试自动化项目。测试用例在本地环境中运行良好,但 JENKINS 构建遇到以下错误。不确定环境之间缺少什么。

我已经按照互联网的指导更改了 POM 中的一些配置。没有任何效果

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:3.0.0-M5:test (default- 
  test) on project Getter_Web_UI: There are test failures/ 
     [ERROR] Please refer to /var/lib/jenkins/workspace/testING/target/surefire-reports for the 
    individual test results.
        [ERROR] Please refer to dump files (if any exist) [date].dump, [date]-jvmRun[N].dump and 
         [date].dumpstream.
       [ERROR] There was an error in the forked process
         [ERROR] org.apache.maven.surefire.booter.SurefireBooterForkException: There was an error in the forked process
   [ERROR]  at org.apache.maven.plugin.surefire.booterclient.ForkStarter.fork(ForkStarter.java:733)
    [ERROR]     at org.apache.maven.plugin.surefire.booterclient.ForkStarter.run(ForkStarter.java:305)
    [ERROR]     at org.apache.maven.plugin.surefire.booterclient.ForkStarter.run(ForkStarter.java:265)
    [ERROR]     at org.apache.maven.plugin.surefire.AbstractSurefireMojo.executeProvider(AbstractSurefireMojo.java:1314)

POM.XML

enter code here<?xml version="1.0" encoding="UTF-8"?>

4.0.0

<groupId>org.TESTING</groupId>
<artifactId>TESTING</artifactId>
<version>1.0-SNAPSHOT</version>

<build>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>3.0.0-M5</version>
                <configuration>
                    <forkCount>3</forkCount>
                    <reuseForks>true</reuseForks>
                    <useSystemClassLoader>false</useSystemClassLoader>
                    <useManifestOnlyJar>false</useManifestOnlyJar>
                    <suiteXmlFiles>
                        <suiteXmlFile>testng.xml</suiteXmlFile>
                    </suiteXmlFiles>
                </configuration>
            </plugin>
        </plugins>
    </pluginManagement>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.7.0</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
           </plugin>
    </plugins>
</build>

<dependencies>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>3.14.0</version>
    </dependency>
    <dependency>
        <groupId>org.testng</groupId>
        <artifactId>testng</artifactId>
        <version>6.14.3</version>
    </dependency>
    <dependency>
        <groupId>io.github.bonigarcia</groupId>
        <artifactId>webdrivermanager</artifactId>
        <version>3.6.1</version>
    </dependency>
    <dependency>
        <groupId>com.aventstack</groupId>
        <artifactId>extentreports</artifactId>
        <version>4.0.6</version>
    </dependency>

    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.7.30</version>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-log4j12</artifactId>
        <version>1.7.30</version>
        <scope>test</scope>
    </dependency>
</dependencies>

【问题讨论】:

  • 正确读取 Surefire 的错误日志。
  • @tibor17 这对我有用,忘记更新答案
  • 为什么你有 falsefalse?不推荐。
  • @tibor17 我已经尝试过互联网上提供的任何选项
  • 我是 Apache 中 Surefire 的开发人员。您应该了解这些设置。许多人不这样做,然后问题就开始了。您使用这些设置有什么问题吗?

标签: java maven jenkins testng maven-surefire-plugin


【解决方案1】:

这些步骤帮助我解决了

  1. 从 jdk16 更新到 Java jdk 8 或 11 以支持 jenkins Build 运行。

  2. 插件管理标签正确对齐。

      <pluginManagement>
       <plugins>
             <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-surefire-plugin</artifactId>
                 <version>3.0.0-M5</version>
                 <configuration>
                     <includes>                                                   
                         <include>Sample.java</include>
                     </includes>
    
                 </configuration>
             </plugin>
    
    
    
         <plugin>
             <groupId>org.apache.maven.plugins</groupId>
             <artifactId>maven-compiler-plugin</artifactId>
             <version>3.7.0</version>
             <configuration>
                 <source>8</source>
                 <target>8</target>
             </configuration>
         </plugin>
    
     </plugins>
    

现在肯定可以选择测试并运行。

【讨论】:

  • 问题是你没有遵守标准。为什么你的测试类是“Sample.java”?它应该是位于 src/test/java/. 中的“SampleTest”
  • @tibor17 sample.java 是我重命名的实际测试类。从 为测试执行挑选并运行的测试用例
  • 如果我的测试使用 java 11 语言特性怎么办?我猜它会中断,因为配置将它设置为 java 1.8
猜你喜欢
  • 2020-03-30
  • 2017-01-23
  • 2020-02-24
  • 2013-10-17
  • 2016-07-25
  • 1970-01-01
  • 1970-01-01
  • 2014-11-03
  • 2012-10-21
相关资源
最近更新 更多