CodeParrot is a continuous testing platform which continuously records production traffic (request / response of your app) and tests your app by replaying the captured requests and comparing responses.

In this tutorial, we will use CodeParrot with a NodeJs application. Our sample application “Paymentservice” contains /charge_card API which takes amount and credit card details as input and returns transaction id. Transaction id is -1 if the inputs are incorrect. Our goal is to test for all the possible scenarios ( example — payment success, incorrect expiry date, incorrect cvv etc)
POST /charge_card
{
"amount": {
"currency_code": "USD",
"units": "346"
},
"credit_card": {
"credit_card_cvv": 452,
"credit_card_expiration_month": 5,
"credit_card_expiration_year": 2025,
"credit_card_number": "4242-4242-4242-4242"
}
}
CodeParrot can be simply installed as a npm package which records the production traffic. Checkout installation instructions here — CodeParrot nodeJS setup
As users start interacting with the API, CodeParrot will automatically start recording unique test cases. To start recording test cases, just require the codeparrot library before starting your app
node -r @codeparrot/js-agent <app_name>.js
The generated test cases for /charge_card API are
// Incorrect credit card number {"amount": {"currency_code": "INR","units": "28750"},"credit_card": {"credit_card_cvv": 789,"credit_card_expiration_month":
5, "credit_card_expiration_year": 2025,"credit_card_number": "4242-4242-4242-42432"}}
// Success {"amount": {"currency_code": "USD","units": "346"},"credit_card": {"credit_card_cvv": 789,"credit_card_expiration_month":
5, "credit_card_expiration_year": 2027,"credit_card_number": "4786-8756-4356-7865"}}
// Expired credit card {"amount": {"currency_code": "USD", "units": "346"},"credit_card": {"credit_card_cvv": 789,"credit_card_expiration_month":
5, "credit_card_expiration_year": 2024,"credit_card_number": "4553-8723-8529-0867"}}
// Incorrect credit card cvv {"amount": {"currency_code": "USD", "units": "346"},"credit_card": {"credit_card_cvv": "a789","credit_card_expiration_month":
5, "credit_card_expiration_year": 2025,"credit_card_number": "4532-0981-4528-0956"}}
Before pushing an update, all the captured test cases can be easily replayed on local machine without any setup ( CodeParrot automatically mocks any downstream dependency with the production response ensuring consistency in production and localhost). To replay the recorded test cases, simply set the following environment variables and restart the app.
CODE_PARROT_IS_REPLAY=true
// Identifier for the test report, test report will be overwritten if this version is same
CODE_PARROT_VERSION=1.0
node -r @codeparrot/js-agent <app_name>.js