当前位置: 首页 > 知识库问答 >
问题:

Maven生成空的surefire报告

慕乐池
2023-03-14

我正在AWS Codebuild/Codedeploy上运行测试,测试完成后,会生成一个Surefire HTML文件,但它是空的。当我在IntelliJ上本地运行测试时(不是通过MVN运行),各种JSON和XML测试报告都可以很好地创建。我完全无法理解为什么在IntelliJ上本地运行时会发生这种情况,而在AWS上通过MVN运行时会返回一个空报告。我完全被这件事困住了。

波姆。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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.emprisautomationtest</groupId>
<artifactId>com.emprisautomationtest</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>com.emprisautomationtest</name>
<description>com.emprisautomationtest</description>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <cucumber.reporting.version>0.0.23</cucumber.reporting.version>
    <maven.cucumber.reporting.version>0.0.6
    </maven.cucumber.reporting.version>
</properties>
<repositories>
    <repository>
        <id>repo.bodar.com</id>
        <url>http://repo.bodar.com</url>
    </repository>
</repositories>
<dependencies>


    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.11</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-core</artifactId>
        <version>1.2.0</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>com.warrenstrange</groupId>
        <artifactId>googleauth</artifactId>
        <version>1.2.0</version>
    </dependency>
    <dependency>
        <groupId>com.jayway.restassured</groupId>
        <artifactId>rest-assured</artifactId>
        <version>2.9.0</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-chrome-driver</artifactId>
        <version>3.141.59</version>
    </dependency>

    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-ie-driver</artifactId>
        <version>3.141.59</version>
    </dependency>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-api</artifactId>
        <version>3.141.59</version>
    </dependency>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-remote-driver</artifactId>
        <version>3.141.59</version>
    </dependency>
    <dependency>
        <groupId>io.github.bonigarcia</groupId>
        <artifactId>webdrivermanager</artifactId>
        <version>3.7.1</version>
    </dependency>
    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-html</artifactId>
        <version>0.2.3</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-java</artifactId>
        <version>1.2.0</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-junit</artifactId>
        <version>1.2.0</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-jvm-deps</artifactId>
        <version>1.0.3</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>gherkin</artifactId>
        <version>2.12.2</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>gherkin-jvm-deps</artifactId>
        <version>1.0.2</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.json</groupId>
        <artifactId>json</artifactId>
        <version>20090211</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>com.google.code.gson</groupId>
        <artifactId>gson</artifactId>
        <version>2.8.0</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind -->
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-databind</artifactId>
        <version>2.9.5</version>
    </dependency>

    <dependency>
        <groupId>com.googlecode.json-simple</groupId>
        <artifactId>json-simple</artifactId>
        <version>1.1.1</version>
    </dependency>

    <dependency>
        <groupId>org.hamcrest</groupId>
        <artifactId>hamcrest-all</artifactId>
        <version>1.3</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.exparity</groupId>
        <artifactId>hamcrest-date</artifactId>
        <version>2.0.7</version>
    </dependency>

    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-server</artifactId>
        <version>3.141.59</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>3.141.59</version>
    </dependency>
    <dependency>
        <groupId>net.masterthought</groupId>
        <artifactId>maven-cucumber-reporting</artifactId>
        <version>${maven.cucumber.reporting.version}</version>
    </dependency>

    <dependency>
        <groupId>net.masterthought</groupId>
        <artifactId>cucumber-reporting</artifactId>
        <version>${cucumber.reporting.version}</version>
    </dependency>

    <dependency>
        <groupId>com.googlecode.totallylazy</groupId>
        <artifactId>totallylazy</artifactId>
        <version>991</version>
    </dependency>

    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-log4j12</artifactId>
        <version>1.7.25</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.17</version>
    </dependency>

    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-api</artifactId>
        <version>2.7</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-core</artifactId>
        <version>2.7</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>com.google.guava</groupId>
        <artifactId>guava</artifactId>
        <version>27.0.1-jre</version>
    </dependency>
    <dependency>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-javadoc-plugin</artifactId>
        <version>3.1.1</version>
        <type>maven-plugin</type>
    </dependency>

    <!-- API, java.xml.bind module -->
    <dependency>
        <groupId>jakarta.xml.bind</groupId>
        <artifactId>jakarta.xml.bind-api</artifactId>
        <version>2.3.2</version>
    </dependency>

    <!-- Runtime, com.sun.xml.bind module -->
    <dependency>
        <groupId>org.glassfish.jaxb</groupId>
        <artifactId>jaxb-runtime</artifactId>
        <version>2.3.2</version>
    </dependency>
    <dependency>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-report-plugin</artifactId>
        <version>3.0.0-M5</version>
        <type>maven-plugin</type>
    </dependency>
</dependencies>

<build>
    <plugins>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-site-plugin</artifactId>
            <version>3.8.2</version>
            <configuration>
                <reports>${project.build.directory}/surefire-report</reports>
            </configuration>
        </plugin>
        <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>
                <encoding>UTF-8</encoding>
                <compilerArgs>
                    <arg>-parameters</arg>
                </compilerArgs>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jxr-plugin</artifactId>
            <version>2.3</version>
        </plugin>
        <plugin>
            <groupId>net.masterthought</groupId>
            <artifactId>maven-cucumber-reporting</artifactId>
            <version>${maven.cucumber.reporting.version}</version>
            <executions>
                <execution>
                    <id>execution</id>
                    <phase>verify</phase>
                    <goals>
                        <goal>generate</goal>
                    </goals>
                    <configuration>
                        <projectName>analysis-ui-test</projectName>
                        <outputDirectory>${project.build.directory}/cucumber-html-reports
                        </outputDirectory>
                        <cucumberOutput>${project.build.directory}/cucumber.json
                        </cucumberOutput>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>
<reporting>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-report-plugin</artifactId>
            <version>3.0.0-M5</version>
        </plugin>
    </plugins>
</reporting>

建筑规范。yml:

version: 0.2

phases:
  build:
    commands:
      - echo Build started on `date`
      - mvn clean verify
  post_build:
    commands:
      - echo Build completed on `date`
      - mvn surefire-report:report
reports:
  arn:aws:codebuild:eu-west-2:161668806093:report-group/empris-automation-test-prod-reportGroupCucumberJson:
    files:
      - 'TEST-com.emprisautomationtest.apiDefinition.RunCukesTest.xml'
    base-directory: 'target'
    discard-paths: yes
artifacts:
  files:
    - '**/*'
cache:
  paths:
    - '/root/.m2/**/*'

编辑:将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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.emprisautomationtest</groupId>
    <artifactId>com.emprisautomationtest</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>com.emprisautomationtest</name>
    <description>com.emprisautomationtest</description>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <cucumber.reporting.version>0.0.23</cucumber.reporting.version>
        <maven.cucumber.reporting.version>0.0.6
        </maven.cucumber.reporting.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>com.jayway.restassured</groupId>
            <artifactId>rest-assured</artifactId>
            <version>2.9.0</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind -->
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>2.9.5</version>
        </dependency>
        <dependency>
            <groupId>com.warrenstrange</groupId>
            <artifactId>googleauth</artifactId>
            <version>1.2.0</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
        </dependency>
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-core</artifactId>
            <version>1.2.0</version>
        </dependency>
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-junit</artifactId>
            <version>1.2.0</version>
        </dependency>
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-java</artifactId>
            <version>1.2.0</version>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-chrome-driver</artifactId>
            <version>3.141.59</version>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-ie-driver</artifactId>
            <version>3.141.59</version>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-api</artifactId>
            <version>3.141.59</version>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-remote-driver</artifactId>
            <version>3.141.59</version>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-server</artifactId>
            <version>3.141.59</version>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>3.141.59</version>
        </dependency>

        <!-- API, java.xml.bind module -->
        <dependency>
            <groupId>jakarta.xml.bind</groupId>
            <artifactId>jakarta.xml.bind-api</artifactId>
            <version>2.3.2</version>
        </dependency>

        <!-- Runtime, com.sun.xml.bind module -->
        <dependency>
            <groupId>org.glassfish.jaxb</groupId>
            <artifactId>jaxb-runtime</artifactId>
            <version>2.3.2</version>
        </dependency>
        <dependency>
            <groupId>net.masterthought</groupId>
            <artifactId>maven-cucumber-reporting</artifactId>
            <version>${maven.cucumber.reporting.version}</version>
        </dependency>
    </dependencies>
    <repositories>
        <repository>
            <id>repo.bodar.com</id>
            <url>http://repo.bodar.com</url>
        </repository>
    </repositories>
    <build>
        <plugins>
            <plugin>
                <groupId>io.github.bonigarcia</groupId>
                <artifactId>webdrivermanager</artifactId>
                <version>3.7.1</version>
            </plugin>
            <plugin>
                <groupId>info.cukes</groupId>
                <artifactId>cucumber-html</artifactId>
                <version>0.2.3</version>
            </plugin>
            <plugin>
                <groupId>info.cukes</groupId>
                <artifactId>cucumber-jvm-deps</artifactId>
                <version>1.0.3</version>
            </plugin>
            <plugin>
                <groupId>info.cukes</groupId>
                <artifactId>gherkin</artifactId>
                <version>2.12.2</version>
            </plugin>
            <plugin>
                <groupId>info.cukes</groupId>
                <artifactId>gherkin-jvm-deps</artifactId>
                <version>1.0.2</version>
            </plugin>
            <plugin>
                <groupId>org.json</groupId>
                <artifactId>json</artifactId>
                <version>20090211</version>
            </plugin>
            <plugin>
                <groupId>com.google.code.gson</groupId>
                <artifactId>gson</artifactId>
                <version>2.8.0</version>
            </plugin>
            <plugin>
                <groupId>com.googlecode.json-simple</groupId>
                <artifactId>json-simple</artifactId>
                <version>1.1.1</version>
            </plugin>
            <plugin>
                <groupId>org.hamcrest</groupId>
                <artifactId>hamcrest-all</artifactId>
                <version>1.3</version>
            </plugin>
            <plugin>
                <groupId>org.exparity</groupId>
                <artifactId>hamcrest-date</artifactId>
                <version>2.0.7</version>
            </plugin>

            <plugin>
                <groupId>net.masterthought</groupId>
                <artifactId>cucumber-reporting</artifactId>
                <version>${cucumber.reporting.version}</version>
            </plugin>

            <plugin>
                <groupId>com.googlecode.totallylazy</groupId>
                <artifactId>totallylazy</artifactId>
                <version>991</version>
            </plugin>
            <plugin>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-log4j12</artifactId>
                <version>1.7.25</version>
            </plugin>
            <plugin>
                <groupId>log4j</groupId>
                <artifactId>log4j</artifactId>
                <version>1.2.17</version>
            </plugin>
            <plugin>
                <groupId>org.apache.logging.log4j</groupId>
                <artifactId>log4j-api</artifactId>
                <version>2.7</version>
            </plugin>
            <plugin>
                <groupId>org.apache.logging.log4j</groupId>
                <artifactId>log4j-core</artifactId>
                <version>2.7</version>
            </plugin>
            <plugin>
                <groupId>com.google.guava</groupId>
                <artifactId>guava</artifactId>
                <version>27.0.1-jre</version>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-javadoc-plugin</artifactId>
                <version>3.1.1</version>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-report-plugin</artifactId>
                <version>3.0.0-M5</version>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-site-plugin</artifactId>
                <version>3.8.2</version>
                <configuration>
                    <reports>${project.build.directory}/surefire-report</reports>
                </configuration>
            </plugin>
            <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>
                    <encoding>UTF-8</encoding>
                    <compilerArgs>
                        <arg>-parameters</arg>
                    </compilerArgs>
                </configuration>
            </plugin>
<!--            <plugin>-->
<!--                <groupId>org.apache.maven.plugins</groupId>-->
<!--                <artifactId>maven-surefire-plugin</artifactId>-->
<!--                <version>2.18.1</version>-->
<!--            </plugin>-->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jxr-plugin</artifactId>
                <version>2.3</version>
            </plugin>
            <plugin>
                <groupId>net.masterthought</groupId>
                <artifactId>maven-cucumber-reporting</artifactId>
                <version>${maven.cucumber.reporting.version}</version>
                <executions>
                    <execution>
                        <id>execution</id>
                        <phase>verify</phase>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
                            <projectName>analysis-ui-test</projectName>
                            <outputDirectory>${project.build.directory}/cucumber-html-reports
                            </outputDirectory>
                            <cucumberOutput>${project.build.directory}/cucumber.json
                            </cucumberOutput>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
    <reporting>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-report-plugin</artifactId>
                <version>3.0.0-M5</version>
            </plugin>
        </plugins>
    </reporting>
</project>

共有1个答案

刁跃
2023-03-14

解决了的!!!

原来yml文件需要以下命令:

mvn -Dtest=RunTests test

运行测试是主测试类的名称。现在一切都正常了。

 类似资料:
  • 如何在maven的默认生命周期中生成surefire报告。我们在teamcity设立了工作岗位,目标如下 这个作业运行所有junits,我想创建项目中运行的所有测试的HTML报告。我遇到了sure fire reports插件,但它只在站点阶段生成报告,而在默认的干净安装阶段不生成报告。 我如何生成报告默认生命周期 我尝试包括surefire报告插件,在测试阶段如下,但不工作

  • 我被要求并行运行cucumber测试(通过使用maven surefire多个jvms,forkCount)-结果报告相当于通过顺序运行测试创建的报告。 我使用的是cucumberv3。cucumberv4允许使用一个带有组合结果报告的单一运行器并行运行测试——但是我对v4的尝试并没有使我能够使用一个运行器运行多个JVM/生成一个报告。 您能否澄清/建议是否有一种替代/更简单的方法来解决以下问题?

  • 我没有更改Checkstyle、Findbugs、Jacoco或PMD插件配置。我在Surefire插件配置中添加了一些行: 这些是声纳插件: 当运行它时,我会得到这样的消息:“'Sonar.DynamicAnalysis‘is deprecated sund version4.3 and should nower be used”。但我不确定还能用什么。相关的JIRA问题也没有说明这一点(htt

  • 但是,当看到html报告时,这一个显示5分钟的执行时间,在控制台里说是2.5分钟。 我们在sunfire报告中发现,特性son、调用web服务的步骤延迟了30 ms,但调用此特性son的步骤也有30 ms。60毫秒也是如此。 > 呼叫(feature Son.feature)30ms 对不起,我的英语不好。谢谢你的帮助

  • 我试图设置为我的项目的代码覆盖 我的项目基于 下面是我项目的 然后我运行并看到以下内容 然后我运行,我看到 问题 -配置中有什么不正确 -如何生成报告? 谢啦