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 :

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 .

One thought on “Implement Retry in Unit test

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s