This is the age of "Automation". And We, Developers, always try to automate boring tasks!
One of those boring tasks is Testing APIs by making API calls and checking if the response is right or not. But Keploy Solves this Problem pretty well. So in this article, we'll explore what is Keploy, How it works, and how to set it up locally with examples!
So without delaying further, Let's Start!
What is Keploy?
Keploy is an Open Source API testing platform to generate Test cases out of data calls along with data mocks.
In simple words, With Keploy we don't have to write manual test cases. It records API interactions and expected responses and generates test cases and data mocks to make our work easy and efficient.
Before understanding Why we need Keploy, First, understand the problem!
Suppose, We are going to create a complex application. But as the complexity and codebase increases, It's very hard for us to manually write test cases and manage them. It's like a never-ending marathon!
Here comes Keploy! It automates the process of generating test cases and makes it easier for the maintainers to maintain the test cases efficiently. So we can focus on more critical works than writing those bearing test cases.
How keploy works?
So Till now, we know what is keploy and why we need keploy! Now Let's understand how keploy works!
Whenever our application makes an API call, the keploy SDK records the request subsequent network calls to external dependencies, and the expected response. Internally It combines all the information and stores it as a test case in the server.
Now, here's the cool part.
Next time when we'll be working on the new version of that project, Keploy will automatically download the previously captured test cases and run them alongside them.
Not only that Keploy will also compare the actual response with the expected one and throw errors if we have any bugs.
Setting up Keploy Locally
In this Section, We'll set up Keploy locally and generate test cases for a Sample Nodejs application.
Sound Interesting? Right?
First things first, We'll be cloning one sample application from GitHub and move to the samples-typescript/express-mongoose Folder. For that write this in your WSL:
git clone https://github.com/keploy/samples-typescript && cd samples-typescript/express-mongoose
Now, We'll install all the required packages using npm install.
For this project, we'll be using Keploy Natively on WSL.
On Windows, WSL is required to run Keploy Binary. For that, we need Windows 10 version 2004 and higher (Build 19041 and higher) or Windows 11 to use the commands below.
Now, We'll download and Install "Keploy Binary". For that use the following command in your terminal:
Great! Now in Terminal, we can see Keploy has captured the test cases.
In the MongoDB Dashboard, we can also see the data
And Now, In our project, we can see test cases have been generated in the keploy folder.
Great work! We have successfully generated the test cases! Now we can test our APIs with ease!
Celebrate Hacktoberfest with Keploy
October is the month of Open Source and Keploy is taking part in this celebration. You can contribute to several Keploy projects by participating in this year’s Hacktoberfest. You can both contribute to the code part and the no-code part as well. Here are some contributions that you can make!
Code Contributribution includes:
🛠️ Bug fixes
👉 New features
👨💻 Build Sample Apps
Non-code contributions include:
Create a Tutorial
So what are you Waiting for?
Give a Star, Fork the Repository of Keploy and Make Your First Contribution!
As a DevRel Intern at Keploy, a tool for automating writing manual Test cases, I am responsible for creating and delivering engaging and informative web content and technical documentation for our users and partners. I use my skills in web development, content creation, and public relations to produce high-quality tutorials, blogs, videos, podcasts, and newsletters that showcase the features and benefits of our platform and help our users solve their deployment challenges.
I am also a passionate tech blogger and an open-source enthusiast, with over 50 blog posts published on various platforms, reaching over 100,000 views and 10,000 claps. I write on topics such as open source, web development, and data structures and algorithms, to share my knowledge and passion with the tech community. I have also participated in several open source programs and events, such as Hacktoberfest, Google Summer of Code, and MLH Fellowship, where I have contributed to various open source projects and learned from experienced mentors and peers.
I am currently pursuing my B.Tech degrees in Information Technology and Computer Science at MAKAUT and Heritage Institute of Technology, respectively. I am eager to learn new skills and technologies and apply them to real-world problems and solutions. I am also interested in exploring the fields of artificial intelligence, machine learning, and natural language processing, and how they can enhance the user experience and the social impact of web applications. My goal is to become a full-stack developer and a leader in the tech industry.