我正在嘗試將 Cucumber 集成到現有的 Spring Boot 專案中。
當前專案是單個 Maven 模塊。
單元測驗(沒有 Spring 背景關系)和集成測驗(有 Spring 背景關系)組合在同一個測驗檔案夾中。
我想做的是能夠適應我的單元測驗和集成測驗。
但是,一旦我添加了cucumber-spring依賴項(以便能夠在規范旁邊運行 Spring 背景關系),它就會要求檔案夾中的所有測驗都使用@CucumberContextConfiguration.
下面是我的測驗套件配置為獲取測驗規范。
@Suite
@IncludeEngines("cucumber")
@SelectClasspathResource("org/example/project")
@ConfigurationParameter(key = PLUGIN_PROPERTY_NAME, value = "pretty")
public class CucumberTest {
}
是否可以將兩種測驗結合起來?如果是如何?
有關我正在使用的資訊:
- 黃瓜 7.1.0
- Spring 平臺套件 1.8.2
- JUnit 5.8.2
uj5u.com熱心網友回復:
您可以通過cucumber.object-factory屬性控制使用的物件工廠。因此,假設您有一個或多個物件工廠作為您的依賴項:
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-spring</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-picocontainer</artifactId>
<scope>test</scope>
</dependency>
然后你可以選擇彈簧:
@ConfigurationParameter(key = OBJECT_FACTORY_PROPERTY_NAME, value = "io.cucumber.spring.SpringFactory")
具有以下功能的 Pico 容器:
@ConfigurationParameter(key = OBJECT_FACTORY_PROPERTY_NAME, value = "io.cucumber.picocontainer.PicoFactory")
或自 v7.1 起,均不具備:
@ConfigurationParameter(key = OBJECT_FACTORY_PROPERTY_NAME, value = "io.cucumber.core.backend.DefaultObjectFactory")
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/403270.html
標籤:
