将以下插件添加到我的 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>
由于您没有显示所有配置,我猜您可能会错过
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
将生成 Cucumber 报告文件
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
一起做
请尝试使用下面的代码片段。只需在标签中给出 json 文件的路径。在我的例子中,它在目标文件夹中,所以我使用了下面的代码并且它对我有用。希望这可以帮助!
<configuration>
<projectName>ExecutionResult</projectName>
<outputDirectory>${project.build.directory}/cucumber-report-html</outputDirectory>
<inputDirectory>${project.build.directory}</inputDirectory>
<jsonFiles>
<param>**/*.json</param>
</jsonFiles>
</configuration>
对于集成测试,如果您使用的是 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与黄瓜报告插件一起使用所以不知道它是否适用于以下conf.
还在
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-test
或mvn verify
生成报告。这是为了集成测试。
我遇到了同样的问题并用这个配置解决了。
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.techarchive</groupId>
<artifactId>cucumberReporting</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>cucumberReporting</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url>
<properties>
<java.version>1.8</java.version>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<version>4.4.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.masterthought</groupId>
<artifactId>cucumber-reporting</artifactId>
<version>5.6.1</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>3.8.3</version>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>6.9.1</version>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<version>6.9.1</version>
</dependency>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
<configuration>
<testFailureIgnore>true</testFailureIgnore>
<includes>
<include>"**/Step*.java"</include>
</includes>
</configuration>
</plugin>
<plugin>
<groupId>net.masterthought</groupId>
<artifactId>maven-cucumber-reporting</artifactId>
<version>5.6.0</version>
<executions>
<execution>
<id>execution</id>
<phase>verify</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<projectName>web-cucumber</projectName>
<!-- optional, per documentation set this to "true" to bypass generation of Cucumber Reports entirely, defaults to false if not specified -->
<skip>false</skip>
<!-- output directory for the generated report -->
<outputDirectory>${project.build.directory}
</outputDirectory>
<!-- optional, defaults to outputDirectory if not specified -->
<inputDirectory>${project.build.directory}
</inputDirectory>
<jsonFiles>
<!-- supports wildcard or name pattern -->
<param>**/*.json</param>
</jsonFiles>
<!-- optional, defaults to outputDirectory if not specified -->
<!-- <classificationDirectory>${project.build.directory}/classifications</classificationDirectory> -->
<!-- <classificationFiles> -->
<!-- supports wildcard or name pattern -->
<!-- <param>sample.properties</param> -->
<!-- <param>other.properties</param> -->
<!-- </classificationFiles> -->
<!-- <parallelTesting>false</parallelTesting>-->
<!-- optional, set true to group features by its Ids -->
<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>
</plugins>
</build>
</project>
功能、测试运行程序和步骤没有变化。
我使用 Eclipse IDE 生成报告只需按照以下步骤操作