The API layer is one of the most crucial components in a microservice-based application. It is the channel that connects one microservice to another, drives business processes, and provides the services which give value to users. API is essentially an agreed contract between two services. Before any implementation test can begin, it is important to make sure that your written component behaves as the agreed contract.

In this article, we will learn how to write a unit test for FeignClient using SpringBootTest to set up our test context, a RestController to fake the remote API, and a RibbonClient to feed our FeignClient with a fake remote endpoint URL.

Introduction

Let’s consider here that we have a Spring Boot application with Client Discovery feature enabled and a FeignClient that has a GET and POST request method.

#spring-cloud #unittest #spring-boot #openfeign #spring

Feign Client —Unit Testing
3.20 GEEK