我的黄瓜测试每次通过都会刷新spring boot上下文,我已经完成了一些数据库缓存,这正在破坏编译过程的性能。
我的抽象测试通过@ContextConfiguration(loader = SpringBootContextLoader.class)标记为@SpringBootTest(defined_port)。
我已经尝试添加DirtiesContext,但是它没有用...任何想法?
[如果您使用最新的Cucumber(v5.7.0)使Cucumber知道您的测试配置,则可以使用@CucumberContextConfiguration
和以下注释之一在胶粘路径上注释配置类:@ContextConfiguration
,[C0 ]或@ContextHierarchy
。如果您使用的是SpringBoot,则可以使用@BootstrapWith
例如:
@SpringBootTest
然后您可以从应用程序上下文中将import com.example.app;
import org.springframework.boot.test.context.SpringBootTest; import io.cucumber.spring.CucumberContextConfiguration;
@CucumberContextConfiguration
@SpringBootTest(classes = TestConfig.class) public class
CucumberSpringConfiguration { }
组件放入任何步骤定义文件中。无需其他弹簧配置。例如:
@Autowire
唯一的要求是package com.example.app;
public class MyStepDefinitions {
@Autowired
private MyService myService;
@Given("feed back is requested from my service")
public void feed_back_is_requested(){
myService.requestFeedBack();
}
}
和MyStepDefinitions
都在粘合路径上的包装中。因此,您已经明确配置了CucumberSpringConfiguration
或测试运行器类与步骤定义(@CucumberOptions(glue="com.example")
)位于同一软件包中。
您可以在github的com.example
模块中找到更多信息。cucumber-spring