【发布时间】:2019-09-19 22:12:07
【问题描述】:
我正在创建一个应该同时利用 Cucumber 和 Spring Boot 平台的小型测试框架。这个想法是让整个应用程序打包为一个 jar,并在 BDD 功能正确参数化后运行。
框架以命令行运行器模式启动,如下所示:
public class FwApplication implements CommandLineRunner {
public static void main(String[] args) {
SpringApplication.run(FwApplication.class, args);
}
@Override
public void run(String... arg0) throws Exception {
JUnitCore.main(CucumberIntegration.class.getCanonicalName());
}
}
然后是 CucumberIntegration 类:
@RunWith(Cucumber.class)
@CucumberOptions(features = "config/features")
@ContextConfiguration(classes= AppConfiguration.class)
public class CucumberIntegration {
}
我还有一些在我的 IDE 下运行良好的简单测试,但是当我尝试打包应用程序并在 java -jar fw-0.0.1-SNAPSHOT.jar 上运行它时,我看到以下内容:
There was 1 failure:
1) initializationError(com.fmr.bddfw.test.CucumberIntegration)
cucumber.runtime.CucumberException: No backends were found. Please make sure you have a backend module on your CLASSPATH.
at cucumber.runtime.Runtime.<init>(Runtime.java:81)
at cucumber.runtime.Runtime.<init>(Runtime.java:70)
(...)
所有必要的 jar 都已经在 maven 创建的一个 jar 中,并且在我的 IDE 下可以正常工作。
有什么可以帮助的想法吗?
编辑:这是我的 pom 文件。
<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.xxx</groupId>
<artifactId>fw</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>fw</name>
<description>BDD Testing Framework</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.3.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<cucumber.version>1.2.5</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>info.cukes</groupId>
<artifactId>cucumber-junit</artifactId>
<version>${cucumber.version}</version>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-spring</artifactId>
<version>${cucumber.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
【问题讨论】:
-
你应该添加 cucumber-java 依赖
-
似乎并非如此。
cucumber-spring取决于cucumber-java。罐子包括在内。它在 IDE 中工作。 :// -
很抱歉恢复这篇文章,但你有没有找到解决办法?我找不到一种方法来执行资源加载器,同时又保持我的测试分开。按照他们目前的情况,我可以在我的 IDE 中运行每一个都很好。我不想破坏一切。
标签: maven spring-boot cucumber-java