Description
Keploy is a functional testing toolkit for developers. It generates E2E tests for APIs (KTests) along with mocks or stubs(KMocks) by recording real API calls.
KTests can be imported as mocks for consumers and vice-versa. Merge KTests with unit testing libraries(like Go-Test, JUnit..) to track combined test-coverage.
KMocks can also be referenced in existing tests or use anywhere (including any testing framework). KMocks can also be used as tests for the server.
Keploy alternatives and similar packages
Based on the "Code Generation" category.
Alternatively, view keploy alternatives based on common mentions on social networks and blogs.
-
Barber
DISCONTINUED. A custom view styling library for Android that generates the obtainStyledAttributes() and TypedArray boilerplate code for you. -
RoboCoP
Pure Java code generation tool for generating a fully functional ContentProvider for Android. -
1. AutoProxy
Annotation Processing Library. Generates proxy class on top of interface/abstract class, that allows to intercept calls. Also known as a design pattern: proxy, delegate, interceptor. -
Anakin
Codegeneration tool for isomorphic server and mobile Go apps with gRPC & Protobuf. Share code between your backend, Android & iOS app! :sun_with_face:
InfluxDB - Purpose built for real-time analytics at any scale.
* Code Quality Rankings and insights are calculated and provided by Lumnify.
They vary from L1 to L5 with "L5" being the highest.
Do you think we are missing an alternative of Keploy or a related project?
README
Welcome to Keploy 👋
Keploy
Keploy is a functional testing toolkit for developers. Currently, it can generate:
- E2E tests for APIs (along with mocks) by recording real API calls. These test files can be imported as mocks for consumers and vice-versa.
- Realistic mocks by capturing real calls and be imported and used anywhere (including any testing framework). These mocks can also be used as tests for the server.
Keploy is testing itself with without writing any test-cases and data-mocks. 😎
Quick Start
The fastest way to start with Keploy is the Gitpod-hosted version. When you're ready, you can install locally or host yourself.
One-click deploy sample URL Shortener application sample with Keploy using Gitpod
Features
Convert API calls from any source to Test-Cases: Keploy captures all the API calls and subsequent network traffic served by the application. You can use any existing API management tools like Postman, Hoppscotch, Curl to generate test-case.
Automatically Mocks Dependencies
Safely replays non-idempotent CRUD operations
Export tests and mocks and maintain alongside existing tests
Common file for tests and mocks: Server tests can be shared with client applications and be imported as mocks and vice versa.
Native interoperability with popular testing libraries like
go-test
. Code coverage will be reported with existing and Keploy recorded test cases and can also be integrated in CI pipelines/infrastructure.Accurate Noise Detection in responses like (timestamps, random values) to ensure high quality tests.
Statistical deduplication ensures that redundant testcases are not generated. WIP (ref #27).
Web Console to visually understand the results, update behaviour and share findings across your team.
Test Export generates and stores testcases(and their mocks) in the project directory or mongoDB cluster. By default, they are stored in project directory.
How it works?
Keploy is added as a middleware to your application that captures and replays all network interaction served to application from any source.
Visit https://docs.keploy.io to read more in detail
Quick Installation
Note that Testcases are exported as files in the repo by default
MacOS
curl --silent --location "https://github.com/keploy/keploy/releases/latest/download/keploy_darwin_all.tar.gz" | tar xz -C /tmp
sudo mv /tmp/keploy /usr/local/bin && keploy
Linux
Linux
curl --silent --location "https://github.com/keploy/keploy/releases/latest/download/keploy_linux_amd64.tar.gz" | tar xz -C /tmp
sudo mv /tmp/keploy /usr/local/bin && keploy
Linux ARM
curl --silent --location "https://github.com/keploy/keploy/releases/latest/download/keploy_linux_arm64.tar.gz" | tar xz -C /tmp
sudo mv /tmp/keploy /usr/local/bin && keploy
The UI can be accessed at http://localhost:6789
Helm chart
Keploy can also be installed to your Kubernetes cluster using the Helm chart available [here](deployment/keploy)
Run Sample application
Demos using Echo/PostgreSQL and Gin/MongoDB are available here. For this example, we will use the Echo/PostgreSQL sample.
git clone https://github.com/keploy/samples-go && cd samples-go/echo-sql
go mod download
Start PostgreSQL instance
docker-compose up -d
Run the application
export KEPLOY_MODE=record && go run handler.go main.go
Generate testcases
To genereate testcases we just need to make some API calls. You can use Postman, Hoppscotch, or simply curl
1. Generate shortned url
curl --request POST \
--url http://localhost:8082/url \
--header 'content-type: application/json' \
--data '{
"url": "https://github.com"
}'
this will return the shortened url. The ts would automatically be ignored during testing because it'll always be different.
{
"ts": 1647802058801841100,
"url": "http://localhost:8082/GuwHCgoQ"
}
2. Redirect to original url from shortened url
curl --request GET \
--url http://localhost:8082/GuwHCgoQ
Integration with native Go test framework
You just need 3 lines of code in your unit test file and that's it!!🔥🔥🔥
Contents of main_test.go
:
package main
import (
"github.com/keploy/go-sdk/keploy"
"testing"
)
func TestKeploy(t *testing.T) {
keploy.SetTestMode()
go main()
keploy.AssertTests(t)
}
Run the testcases
Note: Before running tests stop the sample application
go test -coverpkg=./... -covermode=atomic ./...
this should show you have 74.4% coverage without writing any code!
ok echo-psql-url-shortener 5.820s coverage: 74.4% of statements in ./...
All of these can be visualised here - http://localhost:6789/testlist
Keploy SDK Modes
SDK Modes
The Keploy SDKs modes can operated by setting KEPLOY_MODE
environment variable
Note: KEPLOY_MODE value is case sensitive
There are 3 Keploy SDK modes:
- Off : In the off mode the Keploy SDK will turn off all the functionality provided by the Keploy platform.
export KEPLOY_MODE="off"
- Record mode :
- Record requests, response and all external calls and sends to Keploy server.
- After keploy server removes duplicates, it then runs the request on the API again to identify noisy fields.
- Sends the noisy fields to the keploy server to be saved along with the testcase.
export KEPLOY_MODE="record"
- Test mode :
- Fetches testcases for the app from keploy server.
- Calls the API with same request payload in testcase.
- Mocks external calls based on data stored in the testcase.
- Validates the responses and uploads results to the keploy server
export KEPLOY_MODE="test"
Language Support
- [x] Go SDK
- [x] Java SDK
- [x] Typescript/Javascript SDK
- [ ] Python SDK - WIP #58
Need another language support? Please raise an issue or discuss on our slack channel
Current Limitations
- Async operations: Currently Keploy stores dependencies in an array and expects them to be executed in the same order (FIFO). This means if the order of dependency execution changes (typical in async), keploy would likely throw an error. This is generally fine for E2E tests since the responses are generally unaffected. We plan to fix this by using a map instead in the future.
- Unit Testing: While Keploy is designed to run alongside unit testing frameworks (Go test, JUnit..) and can add to the overall code coverage, it still generates E2E tests. So it might be easier to write unit tests for some methods instead of E2E tests.
- K8S CRDs Keploy generates yamls for test and mocks which share a similar structure to K8s CRDs. However, they cannot be installed on kubernetes.
- Production usage Keploy is currently focused on generating tests for developers. These tests can be captured from any environment, but we have not tested it on high volume production environments. This would need robust deduplication to avoid too many redundant tests being captured. We do have ideas on building a robust deduplication system #27
- De-noise requires mocking Keploy issues a duplicate request and compares the responses with the previous responses to find "noisy" or non-deterministic fields. We have to ensure all non-idempotent dependencies are mocked/wrapped by Keploy to avoid unnecessary side effects in downstream services.
Resources
🤔 FAQs
🕵️️ Why Keploy
Community Support ❤️
We'd love to collaborate with you to make Keploy great. To get started:
📌 Our valuable Contributors👩💻👨💻 :
Thanks goes to these wonderful people (emoji key): <!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section --> <!-- prettier-ignore-start --> <!-- markdownlint-disable -->
Shubham Jain🚧 Sarthak🚧 Ritik Jain🚧 Neha Gupta🚧 Felix-Ayush🚧 Madhav Sikka🚧 Unnati🚧 Sid Shukla🚧 Peter Georgas🚧 Michael Grigoryan🚧 Surya Kant🚧 Mahesh Gupta🚧 Naman Taneja🚧 Rajat Sharma🚧 Axit Patel🚧 Tushar Malik🚧
<!-- markdownlint-restore --> <!-- prettier-ignore-end --> <!-- ALL-CONTRIBUTORS-LIST:END -->
Launching keploy Rewards
Contributed to keploy? Here is a big thank you from our community to you. Claim your badge and showcase them with pride. Let us inspire more folks !
### Claim Now!