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

sni*_*ikt 2 cucumber pom.xml maven

将以下插件添加到我的 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>
Run Code Online (Sandbox Code Playgroud)

Sub*_*mal 10

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

假设以下结构

pom.xml
src/test/java/TestRunner.java
src/test/java/stepdefs/StepDefinitions.java
src/test/resource/features/demo.feature
Run Code Online (Sandbox Code Playgroud)

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>
Run Code Online (Sandbox Code Playgroud)

测试运行器.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 {
}
Run Code Online (Sandbox Code Playgroud)

步骤定义.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();
    }
}
Run Code Online (Sandbox Code Playgroud)

演示功能

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
Run Code Online (Sandbox Code Playgroud)

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

target/cucumber.json
Run Code Online (Sandbox Code Playgroud)

运行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/...
Run Code Online (Sandbox Code Playgroud)

跑步mvn clean verify可以解决所有问题


小智 7

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

 <configuration>
     <projectName>ExecutionResult</projectName>
     <outputDirectory>${project.build.directory}/cucumber-report-html</outputDirectory>
     <inputDirectory>${project.build.directory}</inputDirectory>
     <jsonFiles>
          <param>**/*.json</param>
     </jsonFiles>
</configuration>
Run Code Online (Sandbox Code Playgroud)