maven-cucumber-reporting插件未生成报告-没有任何反应

时间:2018-07-10 04:21:44

标签: maven cucumber pom.xml

将以下插件添加到我的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>

3 个答案:

答案 0 :(得分:2)

请尝试使用下面的代码片段,只需在标签中给出json文件的路径即可。就我而言,它位于目标文件夹中,因此我使用了下面的代码,它对我有用。希望这可以帮助!

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

答案 1 :(得分:1)

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

假设以下结构

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将生成黄瓜报告文件

target/cucumber.json

运行mvn verify -DskipTests将基于cucumber-report-html

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

运行mvn clean verify将一起完成

答案 2 :(得分:0)

对于集成测试,如果您使用的是 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 运行,并且您正在使用 Cucumber 进行集成测试(我没有使用带有 Cucumber 报告插件的 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 生成报告。这是用于集成测试。