java - Cucumber + Java + Spring Boot = 从 jar 运行时没有后端错误
问题描述
与这篇较早的帖子类似,我有一个使用 Spring boot 和 Cucumber 的 Java 应用程序。
这个应用程序的目的是使用 Selenium 来验证我的团队使用的一些工具,所以我的测试都在主要范围内。
测试在 IDE 中运行良好,但是当我打包我的 jar 并尝试运行它时,我得到没有找到后端。请确保您的 CLASSPATH 上有一个后端模块。
经过一番搜索,我配置了 spring-boot-maven-plugin 以解压 cucumber-java 依赖项。这修复了“无后端”错误,但是现在,当我运行 jar 时,我在控制台上打印了我的功能文件,但没有真正执行测试(它运行得太快了,我什至引入了一个错误,但它还是成功完成了.
我的pom:
<properties>
<cucumber.version>4.7.1</cucumber.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<version>${cucumber.version}</version>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-spring</artifactId>
<version>${cucumber.version}</version>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>${cucumber.version}</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.141.59</version>
</dependency>
<dependency>
<groupId>com.codeborne</groupId>
<artifactId>phantomjsdriver</artifactId>
<version>1.4.4</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<requiresUnpack>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
</dependency>
</requiresUnpack>
</configuration>
</plugin>
</plugins>
</build>
我的主要课程:
@SpringBootApplication
public class ExecutableMain implements CommandLineRunner {
public static void main(String[] args) {
SpringApplication.run(ExecutableMain.class, args);
}
@Override
public void run(String... args) {
for (String arg : args) {
...
}
Result result = JUnitCore.runClasses(Test1.class, Test2.class, Test3.class);
if (result.wasSuccessful()) {
System.out.println("Success!");
} else {
System.out.println("Failure!");
for (Failure failure : result.getFailures()) {
System.out.println(failure.toString());
}
}
}
}
测试之一?
@RunWith(Cucumber.class)
@CucumberOptions(
plugin = {"pretty", "html:target/cucumber-test1", "json:target/cucumber-test1/cucumber.json"},
glue = {"cucumber.test1", "cucumber.steps"},
features = "src/main/resources/cucumber/test1/"
)
public class Test1 {
}
控制台结果:
INFO 15724 --- [ main] cucumber.ExecutableMain : Starting ExecutableMain
INFO 15724 --- [ main] cucumber.ExecutableMain : No active profile set, falling back to default profiles: default
INFO 15724 --- [ main] cucumber.ExecutableMain : Started ExecutableMain in 4.546 seconds (JVM running for 8.234)
INFO 15724 --- [ main] c.runtime.java.ObjectFactoryLoader : Loading ObjectFactory via service loader: io.cucumber.spring.SpringFactory
Feature: my test feature
Validates stuff
Scenario: my test scenario
Given foo
Then Bar
...
Success!
解决方案
推荐阅读
- python - 绘制每个日期的发生次数
- java - java spring ws: webServiceTemplate.marshalSendAndReceive 发送前签署文件
- azure - 在 AKS 虚拟节点上运行 Azure Functions 的性能
- docker - 从 docker 容器连接到 ubuntu 端口
- docker - 运行 docker-compose up 时可以附加到集群中的单个容器吗?
- git - Git状态:显示模式(权限)更改
- c++ - 升级Qt5.4.1到5.12.1,现在QCodec给出异常
- sql - SQL 违反 UNIQUE KEY 约束但条目不存在?
- c++ - 为什么未使用的成员模板函数的类模板实例化失败
- php - PHPMailer 添加附件