春季启动黄瓜测试

问题描述 投票:1回答:3

我尝试执行一些Spring启动应用程序的Cucumber测试。

在测试运行之前,似乎没有启动Spring Boot。

我错过了什么?

https://bitbucket.org/oakstair/spring-boot-cucumber-example

spring-boot cucumber
3个回答
1
投票

我的Cucumber回购仍然没有完成上述所有步骤:

https://github.com/BarathArivazhagan/Cucumber-spring-integration

文件:https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-testing.html

要添加更多:

  1. @SpringBootTest负责加载应用程序上下文,在这种情况下@ContextConfiguration是还原剂。
  2. Spring测试自动提供了一个可以自动装配的TestRestTemplate bean,但它仍然可以与RestTemplate一起使用。
  3. 它仍然在没有RANDOM_PORT的情况下运行,但RANDOM端口也可以结合使用进行测试。

1
投票

假设你在feature1中有一个特征文件,glueCodeorg.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
投票

我发现了问题,并更新了回购。

我做了以下工作让它工作:

  • RANDOM_PORT添加到@SpringBootTest
  • 添加了@ContextConfiguration
  • RestTemplate切换到TestRestTemplate
© www.soinside.com 2019 - 2024. All rights reserved.