【问题标题】:maven-cucumber-reporting plugin is not generating the report - nothing happensmaven-cucumber-reporting 插件未生成报告 - 没有任何反应
【发布时间】:2018-12-17 19:50:50
【问题描述】:

将以下插件添加到我的 pom.xml 时,应该在我的目标文件夹中生成报告,但没有生成任何内容。我的项目只是在没有任何报告的情况下运行并完成。有人可以检查一下是否有任何错误吗?

                 <plugin>
                    <groupId>net.masterthought</groupId>
                    <artifactId>maven-cucumber-reporting</artifactId>
                    <version>2.8.0</version>
                    <executions>
                        <execution>
                            <id>execution</id>
                            <phase>verify</phase>
                            <goals>
                                <goal>generate</goal>
                            </goals>
                            <configuration>
                                <projectName>CucumberWebGui</projectName>
                                <outputDirectory>${project.build.directory}/cucumber-report-html</outputDirectory>
                                <cucumberOutput>${project.build.directory}/cucumber.json</cucumberOutput>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>

【问题讨论】:

  • 你执行了 Maven verify 目标了吗?您正在执行哪个 Maven 目标?
  • @SubOptimal 是的,我已经从命令行执行了验证目标。当我查看输出时,我什至没有看到 maven 执行该插件,所以我很困惑为什么 bc 这很简单
  • @SubOptimal net.masterthought 的 github 指令没有引用除 pom 之外的任何其他更改(即没有更改 runner)。我不明白为什么这对除我以外的所有人都有效
  • 不是这个插件的问题。您需要注意您指定的输入文件cucumber.json,因为它是以某种方式生成的。在我的答案下方查看我的评论。

标签: maven cucumber pom.xml


【解决方案1】:

由于您没有显示所有配置,我猜您可能会错过 Runner 类中的 plugin 配置。在下面找到一个工作项目。

假设以下结构

pom.xml
src/test/java/TestRunner.java
src/test/java/stepdefs/StepDefinitions.java
src/test/resource/features/demo.feature

pom.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>com.suboptimal</groupId>
    <artifactId>cuke-test.so</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>

    <dependencies>
        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-java8</artifactId>
            <version>3.0.2</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-junit</artifactId>
            <version>3.0.2</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.22.0</version>
                <configuration>
                    <testFailureIgnore>true</testFailureIgnore>
                </configuration>
            </plugin>
            <plugin>
                <groupId>net.masterthought</groupId>
                <artifactId>maven-cucumber-reporting</artifactId>
                <version>2.8.0</version>
                <executions>
                    <execution>
                        <id>execution</id>
                        <phase>verify</phase>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
                            <projectName>CucumberWebGui</projectName>
                            <outputDirectory>${project.build.directory}/cucumber-report-html</outputDirectory>
                            <cucumberOutput>${project.build.directory}/cucumber.json</cucumberOutput>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

TestRunner.java

import org.junit.runner.RunWith;

import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;

@RunWith(Cucumber.class)
@CucumberOptions(
        features = {"src/test/resource/features"},
        glue = {"stepdefs"},
        plugin = {"json:target/cucumber.json"})
public class TestRunner {
}

StepDefinitions.java

package stepdefs;

import org.junit.Assert;

import cucumber.api.java.en.Given;

public class StepDefinitions {
    @Given("^a successful step$")
    public void aSuccessfulStep() throws Throwable {
        System.out.println("a successful step");
    }

    @Given("^a not successful step$")
    public void aNotSuccessfulStep() throws Throwable {
        System.out.println("a not successful step");
        Assert.fail();
    }
}

demo.feature

Feature: Test cucumber reporting plugin

  Scenario: Run a non failing scenario
    Given a successful step

  Scenario: Run a failing scenario
    Given a not successful step

运行mvn clean test会生成Cucumber报告文件

target/cucumber.json

运行mvn verify -DskipTests 将根据cucumber.json 生成cucumber-report-html

target/cucumber-report-html/cucumber-html-reports/src-test-resource-features-demo-feature.html
target/cucumber-report-html/cucumber-html-reports/...

运行mvn clean verify 将一起完成所有工作

【讨论】:

  • 为什么运行器中的插件配置只引用 json 输出而不是 html?.....仅供参考,我的 pom 中有以下内容 - maven-surefire-plugin
  • @Time_is_an_illusion 在maven-cucumber-reporting 的插件配置中,选项outputDirectory 指定插件将存储其生成的输出的目录,而选项cucumberOutput 指定用作输入的JSON 文件通过这个插件。该文件需要以某种方式生成,例如通过 Cucumber 内置插件,因此是 runner 类中的选项。选项json: 指定要使用的cucumber.runtime.formatter.JSONFormatter。它监听 Cucumber 事件并生成输出文件。如果你不指定任何插件,你不会得到任何输出
【解决方案2】:

请尝试使用下面的代码sn-p。只需在标签中给出json文件的路径即可。在我的情况下,它位于目标文件夹内,所以我使用了下面的代码,它对我有用。希望这可以帮助!

 <configuration>
     <projectName>ExecutionResult</projectName>
     <outputDirectory>${project.build.directory}/cucumber-report-html</outputDirectory>
     <inputDirectory>${project.build.directory}</inputDirectory>
     <jsonFiles>
          <param>**/*.json</param>
     </jsonFiles>
</configuration>

【讨论】:

    【解决方案3】:

    如果您使用 maven 故障安全插件进行集成测试,请确保您已在故障安全配置的配置中传递了环境变量,因为故障安全不会从诸如 junit-platform.properties 之类的属性文件中选择任何值,示例配置是故障安全配置如下

    故障保护

                   <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-failsafe-plugin</artifactId>
                        <configuration>
                            <systemPropertyVariables>
                                <environmentHost>localhost</environmentHost>
                                <environmentPort>8082</environmentPort>
                                <!--IMPORTANT :  failsafe plugin will not read any property files -->
                                <!-- It will ignore the values from junit-platform.properties, so you have to provide it-->
                                <spring.profiles.active>docker-integration-tests</spring.profiles.active>
                                <cucumber.filter.tags>@regression</cucumber.filter.tags>
                                <cucumber.plugin>html:target/jsonReports/cucumber-report.html, json:target/jsonReports/cucumber.json, junit:target/jsonReports/cucumber.xml, pretty</cucumber.plugin>
                            </systemPropertyVariables>
                            <parallel>none</parallel>
                            <classesDirectory>${project.build.testOutputDirectory}</classesDirectory>
                            <classpathDependencyExcludes>
                                <classpathDependencyExcludes>${project.groupId}:${project.artifactId}</classpathDependencyExcludes>
                            </classpathDependencyExcludes>
                            <additionalClasspathElements>
                                <additionalClasspathElement>${project.build.outputDirectory}
                                </additionalClasspathElement>
                            </additionalClasspathElements>
                        </configuration>
                        <executions>
                            <execution>
                                <id>failsafe-integration-tests</id>
                                <phase>post-integration-test</phase>
                                <goals>
                                    <goal>integration-test</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin> 
    

    假设你所有的单元测试类都以*Test.java结尾 并且集成测试使用*IT.java 运行,并且您正在使用黄瓜进行集成测试(我没有使用带有黄瓜报告插件的surefire,所以不知道它是否可以使用以下配置。

    同样在feature 文件中将注释@regression 作为黄瓜在执行期间识别测试的第一行。示例如下

    @regression
    Feature: Wiremock the your controller for Integration test
    

    现在的黄瓜报告插件来自:

    net.masterthought

    插件版本:5.4.0

                  <plugin>
                        <groupId>net.masterthought</groupId>
                        <artifactId>maven-cucumber-reporting</artifactId>
                        <version>${maven-cucumber-reporting.version}</version>
                        <executions>
                            <execution>
                                <id>execution-dwp-employment-income-api</id>
                                <goals>
                                    <goal>generate</goal>
                                </goals>
                                <!-- report generation is happening at this phase, so please dont change-->
                                <phase>integration-test</phase>
                                <configuration>
                                    <projectName>${project.name}</projectName>
                                    <skip>false</skip>
                                    <!-- output directory for the generated report -->
                                    <outputDirectory>${project.build.directory}/jsonReports/reports</outputDirectory>
                                    <!-- optional, defaults to outputDirectory if not specified -->
                                    <inputDirectory>${project.build.directory}/jsonReports</inputDirectory>
                                    <jsonFiles>
                                        <!-- supports wildcard or name pattern -->
                                        <param>**/*.json</param>
                                    </jsonFiles>
                                    <mergeFeaturesById>false</mergeFeaturesById>
                                    <!-- optional, set true to get a final report with latest results of the same test from different test runs -->
                                    <mergeFeaturesWithRetest>false</mergeFeaturesWithRetest>
                                    <!-- optional, set true to fail build on test failures -->
                                    <checkBuildResult>false</checkBuildResult>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
    

    现在使用mvn post-integration-testmvn verify 生成报告。这是用于集成测试。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-02-05
      • 1970-01-01
      • 2018-11-25
      • 2014-12-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多