我尝试对Spring启动应用程序执行一些Cucumber测试。
在测试运行之前,似乎没有启动Spring Boot。
我缺少什么?
答案 0 :(得分:2)
我们假设您在feature1
glueCode
和org.xyz.feature1
@RunWith(Cucumber.class)
@CucumberOptions(
plugin = {"pretty"},
features = "src/test/java/resources/feature/feature1",
glue = {"org.xyz.feature1"})
public class CucumberTest {
}
@RunWith(SpringRunner.class)
@SpringBootTest(classes = {Application.class},
webEnvironment = WebEnvironment.RANDOM_PORT)
@ContextConfiguration
@Ignore
@Transactional
public class FeatureTest extends CucumberTest {
@LocalServerPort
int randomServerPort;
@Given("........")
public void test_1 {
}
}
答案 1 :(得分:1)
我发现了问题并更新了回购。
我做了以下工作以使其正常工作:
RANDOM_PORT
添加到@SpringBootTest
@ContextConfiguration
RestTemplate
切换到TestRestTemplate
答案 2 :(得分:1)
我的Cucumber回购仍然在没有完成上述所有步骤的情况下运行:
https://github.com/BarathArivazhagan/Cucumber-spring-integration
文档:https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-testing.html
添加更多内容:
@SpringBootTest
负责加载应用程序上下文,@ContextConfiguration
是还原剂。
Spring测试会自动提供一个TestRestTemplate
的bean,它可以自动连接,但它也应该与RestTemplate配合使用。
它仍然在没有RANDOM_PORT
的情况下运行,但RANDOM端口也可以结合使用进行测试。