我使用Sping Boot 3,我想使用JUnit/Cucumber运行测试。在执行测试时无法启动应用。
我有这个stacktrace:
io.cucumber.core.backend.CucumberBackendException:请使用一些上下文配置来注解胶水类。
举例来说:
@CucumberContextConfiguration @SpringBootTest(classes = TestConfig.class)public class CucumberSpringConfiguration { }或者:
@CucumberContextConfiguration @ContextConfiguration(.)
public class Uncategorized {
我想知道我如何才能配置它工作得很好。
下面是我的测试入口类:
package com.alten.shop;
import io.cucumber.java.en.Given;
import io.cucumber.junit.Cucumber;
import io.cucumber.junit.CucumberOptions;
import io.cucumber.spring.CucumberContextConfiguration;
import org.junit.Assert;
import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ContextConfiguration;
@RunWith(Cucumber.class)
@CucumberOptions(
monochrome = true,
features = { "classpath:features/products.feature" },
glue = { "com.alten.shop.steps" },
plugin = {"pretty", "json:target/cucumber-report.json"}
)
@CucumberContextConfiguration
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class ShopApplicationTests {
}
字符串
可以识别定义步骤,但配置不正确。
我在StepDefinitions类型上没有任何注解,只有@Given
,@When
和@Then
方法注解来适应功能:
public class StepDefinitions {
}
型
这是我的pom.xml:
<properties>
<java.version>17</java.version>
<jjwt.version>0.11.5</jjwt.version>
<swagger.version>2.6.0</swagger.version>
<cucumber.version>7.14.1</cucumber.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>${cucumber.version}</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-junit -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<version>${cucumber.version}</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-spring -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-spring</artifactId>
<version>${cucumber.version}</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-junit-platform-engine -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit-platform-engine</artifactId>
<version>${cucumber.version}</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient -->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.14</version>
</dependency>
</dependencies>
型
有人能帮帮我吗?
1条答案
按热度按时间h4cxqtbf1#
您已经指示Cucumber在
steps
包中查找胶水:字符串
但是,用
@CucumberContextConfiguration
注解的类在com.alten.shop
包中。这样小 cucumber 就找不到了
您可以删除粘合(cucumber将默认为runner类的包),或者将
@CucumberContextConfiguration
和@SpringBootTest
注解移动到一个单独的类steps
包。