黄瓜+ WebTestClient

时间:2018-08-02 23:19:04

标签: spring-boot junit4 spring-webflux cucumber-java cucumber-junit

我正在尝试在Spring Boot项目model.load_model()中使用Webflux和Cucumber为Controller配置一个简单的黄瓜测试。

我的步骤定义如下:

enter code here

但是我仍然无法获得连接WebTestClient的上下文(我在@ContextConfiguration(classes = TestApp.class, loader = SpringBootContextLoader.class) @AutoConfigureWebTestClient public class StepDefs { @Autowired private WebTestClient webClient; @Given("^an input$") public void anInput(){ //sets the body for the request } @When("^invokes '(.+)' using the method '(.+)'$") public void invokesUsingMethod(String uri, String method){ //sets de uri and method } @Then("^must obtain a (\\d+) response code$") public mustObtainResponseCode(int responseCode){ webClient.method(method) .uri(uri) .body( BodyInserters.fromObject(body) ) .exchange() .expectStatus().isEqualTo(code); } } 方法的第一行得到了NullPointerException),所以我的controller.feature可以按预期工作:

mustObtainResponseCode

按照建议,我还有一个用于配置Cucumber的类:

Feature: Test a Controller

  Scenario: insert a new object
    Given: an input
    When invokes '/controller-mapping' using the method 'POST'
    Then must obtain a 201 response code

在此先感谢您的帮助!

0 个答案:

没有答案