Member-only story
Create your own Mock API for API testing
In this article, we will see how to create our own mock APIs and integrate them into the Framework. A mock API server is useful during development and testing when live data is either unavailable or unreliable. While designing an API, you can use mock APIs to work concurrently on the front and back-end, as well as to gather feedback from developers.
In order to accomplish this, we will create one “.bat” file, one “. json” file, and one test class/method.
First of all, I need to point out that I will not touch on API tests and Framework setup, as this is not the subject of this article. I will create an example so that it can be adapted to any kind of Framework. I continue assuming you already have a Framework. If not, you can create a simple Framework to test it. You can run the class/method that we will create, either with JUnit @Test annotation or from the Runner Class by connecting it to the Cucumber step (Assuming a Selenium Framework).
The logic is the same and easy for all Frameworks. The method that we will prepare should be invoked before we start testing with a local mock API server with @Before annotation in Hook Class or as a Cucumber Given step of the API test scenario. Thus, it will be activated before sending requests and waiting for a response. It’s not Rocket Science, it’s very simple. You can apply…