首页 > 解决方案 > Jenkins 无法使用 Maven Surefire、Spring Boot 和 JUnit5 执行 Cucumber 测试

问题描述

我正在使用Cucumber Runner/Spring Boot/JUnit5 spring-boot-starter-parent:2.2.6.RELEASE/ cucumber-java8:5.6.0Maven Surefire 执行 e2e 测试。我在 Linux VM 上安装了最新的 Jenkins Community LTS v2.222.1 并将我的笔记本电脑连接为从属设备。

当我使用 IDE / 命令提示符在我的笔记本电脑上执行测试时,它工作正常(使用mvn clean test)。但是,当从 Jenkins 触发时,相同的测试不会运行。这有点令人困惑,因为我使用的是相同的配置/工具。

詹金斯控制台 O/P:

[INFO] Changes detected - recompiling the module!
[INFO] Compiling 10 source files to C:\Jenkins\workspace\Sanity\core\target\test-classes
[INFO] 
[INFO] --- maven-surefire-plugin:2.22.2:test (default-test) @ project-core ---
[INFO] 
[INFO] -------------------------------------------------------
[INFO]  T E S T S
[INFO] -------------------------------------------------------
Apr 07, 2020 1:08:45 PM net.masterthought.cucumber.ReportParser parseForFeature
INFO: File {0} does not contain features
Apr 07, 2020 1:08:45 PM net.masterthought.cucumber.ReportParser parseJsonFiles
INFO: File 'C:\Users\User\AppData\Local\Temp\2\cucumber5203280546924184867.json' contains 0 features
Apr 07, 2020 1:08:45 PM net.masterthought.cucumber.ReportBuilder generateErrorPage
INFO: Unexpected error
net.masterthought.cucumber.ValidationException: Passed files have no features!
...

IDE 控制台 O/P:

[INFO] Changes detected - recompiling the module!
[INFO] Compiling 10 source files to C:\Code\project\core\target\test-classes
[INFO] 
[INFO] --- maven-surefire-plugin:2.22.2:test (default-test) @ project-core ---
[INFO] 
[INFO] -------------------------------------------------------
[INFO]  T E S T S
[INFO] -------------------------------------------------------
[INFO] Running com.x.y.z.CucumberTests
2020-04-07 13:22:52.330  INFO   --- [           main] .b.t.c.SpringBootTestContextBootstrapper : Neither @ContextConfiguration nor @ContextHierarchy found for test class [com.x.y.z.stepdefs.LogVerificationSteps], using SpringBootContextLoader
...

CucumberTests.java:

import io.cucumber.junit.Cucumber;
import io.cucumber.junit.CucumberOptions;
import org.junit.runner.RunWith;

@RunWith(Cucumber.class)
@CucumberOptions(
        plugin = {"pretty", "de.monochromata.cucumber.report.PrettyReports:target"},
        features = "src/test/resources/features")
public class CucumberTests {

}

这是多模块 maven 项目,功能如下:

 root
 \__core
  \__src/test/resources/features/*

所以基本上在詹金斯功能/测试中根本没有运行 - 为什么会发生,任何想法的人?

标签: spring-bootjenkinsjunit5cucumber-jvmmaven-surefire-plugin

解决方案


推荐阅读