A sample application that get, create, update, and delete the data of a user in the database (MongoDB for this application).
- Go 1.16 or later
- Docker for running Keploy server
- Thunder Client / Postman Desktop Agent for testing localhost APIs
- Code Editor (VSCode, Sublime Text, etc.)
git clone https://github.com/keploy/samples-go && cd users-profile
go mod download
curl --silent -O -L https://keploy.io/install.sh && source install.shKeploy can be used on Linux, Windows and MacOS through Docker.
Note: To run Keploy on MacOS through Docker the version must be 4.25.2 or above.
Using the docker-compose file we will start our mongodb instance:-
sudo docker-compose up -d mongoNow, we will create the docker image of our application:-
go build -coverkeploy record -c "./app"To genereate testcases we just need to make some API calls. You can use Postman, Hoppscotch, or simply curl
/user: POST - Create a new user in the database/user/:userId: GET - Get a user from the database/user/:userId: PUT - Edit an existing user in the database/user/:userId: DELETE - Delete an existing user from the database/users: GET - Get all users from the database
Post Request
here you can use this object template below for testing:
#you can copy paste this object template:
curl -X POST -H "Content-Type: application/json" -d '{
"username": "Sonichigo",
"name": "Animesh Pathak",
"nationality": "Indian",
"title": "Developer Advocate at Keploy",
"hobbies": "Drumming",
"linkedin": "@sonichigo",
"twitter": "@sonichigo1219"
}' "http://localhost:8080/user"Once done, you can see the Test Cases on the Keploy server, like this:
Now that we have our testcase captured, run the test file.
keploy test -c "./app" --goCoverage --delay 10Once done, we can see that there is a noise present in our testcase:
Let's add body.data.InsertedID: [] under noise in test-1.yaml on line 43
Now let's run the test mode once again: -
Voila! Our testcases have passed🥳 . We can also notice that by capturing just few API calls we got around 87.5% of aggregated coverage with keploy generated testcases
If you like the sample application, Don't forget to star us ✨




