Spring boot integration test with cucumber and Jenkins pipeline

Here I am sharing how you can integrate cucumber for behavior driven testing with spring boot integration test and how you collect the reports in Jenkins pipeline.

 

In a sample spring boot app generated from my custom spring boot archetype we will show a small integration test suite with cucumber and spring boot.

Steps to follow are :

1- Add cucumber maven dependencies to your spring boot pom.xml

<!-- Cucumber-->
<dependency>
    <groupId>info.cukes</groupId>
    <artifactId>cucumber-java</artifactId>
    <version>${cucumber-version}</version>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>info.cukes</groupId>
    <artifactId>cucumber-junit</artifactId>
    <version>${cucumber-version}</version>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>info.cukes</groupId>
    <artifactId>cucumber-spring</artifactId>
    <version>${cucumber-version}</version>
    <scope>test</scope>
</dependency>

2- Define cucumber features in your test resources :

Screen Shot 2017-12-03 at 19.00.06

3- How to define the features implementation to be executed with your spring boot app logic :

the feature description :

the feature implementation :

4- How to execute the integration test :

you need to configure the root executor with Cucumber runner as the following:

and the integration test triggering which will be done via spring boot integration test :

5- how to collect the test reports in Jenkins pipeline :

Complete working sample is here :

GitHub: https://github.com/Romeh/spring-boot-sample-app

References :

  1. Cucumber: https://cucumber.io/
  2. Spring boot : https://projects.spring.io/spring-boot/

 

Advertisements

Implement Retry in Unit test

If you are doing an integration test or sanity testing for real application endpoints in continuous delivery process where you hot deploy the application and and you want to trigger some checkups and sanity testing part of your delivery pipeline , how you can add retry logic with delay to unit testing and to your integration test ?

Sample app that include a working demo for it at the following :

https://github.com/Romeh/spring-boot-sample-app

So I will through about how you can do it :

  • We will create annotation to mark the test cases needed to be retried :

  • We will create the implementation using JUnit rules option :

  • sample of how you can use it :

Then when you execute the test and your endpoint is not reachable right away , it will retry again based into your retry configuration .