黄瓜春季整合测试

时间:2020-08-06 13:52:29

标签: java spring testing cucumber bdd

您好,我是这个社区的追随者(对我很有帮助:D), 现在我对使用黄瓜在春季靴中进行整合测试有一些疑问/问题。

好吧,我认为它更多地是关于概念的,集成测试是它用来完全测试应用程序(在这种情况下为api),因此我开发了几个类: BaseStepsDefinition featureRunner BookingApplicationTest.class

BaseStepsDefinition.class:

  @RunWith(SpringRunner.class)
    @SpringBootTest(classes = BookingApplicationTest.class, webEnviroment = SpringBootTest.WebEnviroment.DEFINED_PORT)
public abstract class BaseStepsDefinition{
    //all the stuff like @Steps , needed variables,restTemplate, methods etc..
}

FeatureRunner.class:

  @RunWith(CucumberWithSerenity.class)
  @CucumberOptions(features="src/test/resources/features"))
public class featureRunner{
    //empty
}

BookingApplicationTest.class:

    @Configuration
    @EnableAutoConfiguration
public class BookingApplicationTest{
  @Bean
  public RestTemplate (){
  return new RestTemplate();
  }
}

因此,使用批注@SpringBootTest,我可以站立该应用程序-> bookingApplicationTest ,但是后来当我尝试对我的api进行请求时,这并没有回答我,总是404 ,但是如果我将带有classes参数的注解@SpringBootTest更改为 BookingApplication (真正的,在src / main中),它可以工作,我不明白带有注解的@springboottest的目的是什么,我应该将所有bean添加到bookingApplicationTest?我不知道站立的BookingApplicationTest.class和真实的之间的区别,我如何正确测试?我可以测试真实的吗?或将@SpringBootApplication添加到我的BookingTestApplication中?或者可以从BookingApplicationTest调用中添加真实的主体:

public static void main(String[] args) {
    SpringApplication.run(BookingApplication.class, args);
}

任何帮助将不胜感激!!! 谢谢!如果回复很好,也许我可以向您的地址发送一些eth / nanos :) 认真地我正在搜索小时和小时,但不能正确理解applicationTest的目的以及为什么不起作用...:S

0 个答案:

没有答案