Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/baratharivazhagan/cucumber-spring-integration

spring boot application integrated with cucumber and restdocs
https://github.com/baratharivazhagan/cucumber-spring-integration

cucumber gherkin spring-boot spring-mvc

Last synced: 15 days ago
JSON representation

spring boot application integrated with cucumber and restdocs

Awesome Lists containing this project

README

        

# cucumber-spring-integration
#### spring boot application integrated with cucumber test cases

This sample demonstrates how to write cucumber test cases to test spring boot application using BDD style.

#### Branch Matrix

Choose the branch before proceeding to further sections.


Branch
Spring Boot Version
Cucumber Version


master
2.3.9.RELEASE
6.10.2


2.3.9
2.3.9.RELEASE
6.10.2


2.1.3
2.1.3.RELEASE
4.2.5


1.0.0
2.0.3.RELEASE
1.2.5


1.5.6
1.5.6.RELEASE
1.2.5

### Development Steps :

step 1 : To start with cucumber :

Add the below dependencies to support Spring with Cucumber:

```

6.10.2



io.cucumber
cucumber-java8
${cucumber.version}
test


io.cucumber
cucumber-java
${cucumber.version}
test


io.cucumber
cucumber-junit
${cucumber.version}
test


io.cucumber
cucumber-spring
${cucumber.version}
test


```

step 2: Define the Cucumber Runner Test

```
@RunWith(Cucumber.class)
@CucumberOptions(features = "src/test/resources/features")
public class CucumberRunnerTest {

}
```

step 3 : Create a feature file and define the BDD steps using gherkin language

Example : Feature describing the scenario of creating a customer with customer details

```
Feature: To save the customer with customer details

Scenario: client makes call to POST /customers to save the customer
Given the customer with customer name "barath" and customer id 7777
When the client calls "/customer" with the given details
Then the client receives status code of 200
And the response contains customer name "barath"
```

step 4 : When you run this feature file ```Run as -> Cucumber``` it generates the BDD style of java code.
Using which you can write the service logic.

### SaveCustomerStepDefinitionTest.java :
```java

@Given("^the customer with customer name \"([^\"]*)\" and customer id (\\d+)$")
public void the_customer_with_customer_name_and_customer_id(String customerName, int customerId) throws Throwable {

}

@When("^the client calls \"([^\"]*)\" with the given details$")
public void the_client_calls_customer_save_with_the_given_details(String path) throws Throwable {

}

@Then("^the client receives status code of (\\d+)$")
public void the_client_receives_status_code_of(int statusCode) throws Throwable {

}

@Then("^the response contains customer name \"([^\"]*)\"$")
public void the_response_contains_customer_name(String customerName) throws Throwable {

}

```

step 5 : Run the tests and check the output under output folder

```
mvn test
```