keploy

Unit, API & Integration Testing Agent for Developers. Generate tests, mocks/stubs for your APIs that actually work!

https://github.com/keploy/keploy

Science Score: 64.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
    Links to: arxiv.org
  • Committers with academic emails
    1 of 91 committers (1.1%) from academic institutions
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (11.7%) to scientific vocabulary

Keywords

agentic-ai ai-testing-tool api-testing go go-test golang java-test mock mock-data-generator mock-framework test-automation test-automation-framework test-generation testing testing-library testing-tool testing-tools unit-test unit-testing unit-testing-framework

Keywords from Contributors

vector-database
Last synced: 4 months ago · JSON representation ·

Repository

Unit, API & Integration Testing Agent for Developers. Generate tests, mocks/stubs for your APIs that actually work!

Basic Info
  • Host: GitHub
  • Owner: keploy
  • License: apache-2.0
  • Language: Go
  • Default Branch: main
  • Homepage: https://keploy.io
  • Size: 70.4 MB
Statistics
  • Stars: 10,353
  • Watchers: 34
  • Forks: 1,510
  • Open Issues: 266
  • Releases: 0
Topics
agentic-ai ai-testing-tool api-testing go go-test golang java-test mock mock-data-generator mock-framework test-automation test-automation-framework test-generation testing testing-library testing-tool testing-tools unit-test unit-testing unit-testing-framework
Created almost 4 years ago · Last pushed 4 months ago
Metadata Files
Readme Contributing Funding License Code of conduct Citation Codeowners Security Cla

README-UnitGen.md

keploy logo

⚡️ Generate unit tests with LLMs, that actually works ⚡️

🌟 The must-have tool for developers in the AI-Gen era 🌟


Keploy X Help us reach 20k stars! Keploy CNCF Landscape [![Slack](https://img.shields.io/badge/Slack-4A154B?style=for-the-badge&logo=slack&logoColor=white)](https://join.slack.com/t/keploy/shared_invite/zt-357qqm9b5-PbZRVu3Yt2rJIa6ofrwWNg) [![LinkedIn](https://img.shields.io/badge/linkedin-%230077B5.svg?style=for-the-badge&logo=linkedin&logoColor=white)](https://www.linkedin.com/company/keploy/) [![X](https://img.shields.io/badge/X-%231DA1F2.svg?style=for-the-badge&logo=X&logoColor=white)](https://x.com/keployio)


Keploy-gen uses LLMs to understand code semantics and generates meaningful unit tests. It's inspired by the Automated Unit Test Improvement using LLM at Meta.

Objectives

  • Automate unit test generation (UTG): Quickly generate comprehensive unit tests and reduce the redundant manual effort.

  • Improve edge cases: Extend and improve the scope of tests to cover more complex scenarios that are often missed manually.

  • Boost test coverage: As codebase grows, ensuring exhaustive coverage should become feasible.

Core Components

| Phase | Activities | Tools/Technologies | | ----------------------------- | ------------------------------------------------------------------------------------------------- | ---------------------------------------- | | Code Analysis | Analyze the code structure and dependencies. | Static analysis tools, LLMs | | Prompt Engineering | Generation of targeted prompts to guide the LLM in producing relevant tests. | LLMs, Custom scripts | | Iterative Test Refinement | Cyclic process of refining tests by running them, analyzing coverage, and incorporating feedback. | Testing frameworks (e.g., JUnit, pytest) |

Process Overview

Referred from Meta's research, TestGen-LLM top level architecture.

Test refinement process of unit test generator

Prerequisites

AI model Setup - Set the environment variable API_KEY. export API_KEY=xxxx

API_KEY can be from either of one these: - OpenAI's GPT-4o directly [preferred].

  • Alternative LLMs via litellm.

  • Azure OpenAI

Installation

Install Keploy locally by running the following command:

➡ Linux/Mac

shell curl --silent -O -L https://keploy.io/install.sh && source install.sh

➡ Windows

  • Download and move the keploy.exe file to C:\Windows\System32

NodeJS ➡ Running with Node.js/TypeScript applications

  • Ensure you've set the API key, as mentioned in pre-requisites above:

shell export API_KEY=xxxx

  • Ensure Cobertura formatted coverage reports, edit jest.config.js or package.json:

json // package.json "jest": { "coverageReporters": ["text", "cobertura"], } or

javascript // jest.config.js module.exports = { coverageReporters: ["text", "cobertura"], };

Generating Unit Tests

  • Run the following command in the root of your application.

    • For Single Test File: If you prefer to test a smaller section of your application or to control costs, consider generating tests for a single source and its corresponding test file:

    shell keploy gen --sourceFilePath="<path to source file>" --testFilePath="<path to test file for above source file>" --testCommand="npm test" --coverageReportPath="<path to coverage.xml>"


    - For Entire Application use the following command to generate tests across:

    ⚠️ Warning: Executing this command will generate unit tests for all files in the application. Depending on the size of the codebase, this process may take between 20 minutes to an hour and will incur costs related to LLM usage.

    bash keploy gen --testCommand="npm test" --testDir="test" --coverageReportPath="<path to coverage.xml>"

🎉 You should see improved test cases and code-coverage. ✅ Enjoy coding with enhanced unit test coverage! 🫰

Go → Running with Golang applications

  • Ensure you've set the API key, as mentioned in pre-requisites above:

shell export API_KEY=xxxx

  • To ensure Cobertura formatted coverage reports, add: bash go install github.com/axw/gocov/gocov@v1.1.0 go install github.com/AlekSi/gocov-xml@v1.1.0 #### Generating Unit Tests
  • Run the following command in the root of your application.

    • For Single Test File: If you prefer to test a smaller section of your application or to control costs, consider generating tests for a single source and its corresponding test file:

    shell keploy gen --sourceFilePath="<path to source file>" --testFilePath="<path to test file for above source file>" --testCommand="go test -v ./... -coverprofile=coverage.out && gocov convert coverage.out | gocov-xml > coverage.xml" --coverageReportPath="<path to coverage.xml>"


    - For Entire Application use the following command to generate tests across:

    ⚠️ Warning: Executing this command will generate unit tests for all files in the application. Depending on the size of the codebase, this process may take between 20 minutes to an hour and will incur costs related to LLM usage.

    bash keploy gen --testDir="." --testCommand="go test -v ./... -coverprofile=coverage.out && gocov convert coverage.out | gocov-xml > coverage.xml" --coverageReportPath="<path to coverage.xml>"

    🎉 You should see improved test cases and code-coverage. ✅ Enjoy coding with enhanced unit test coverage! 🫰

→ Setup for Other Languages

  • Ensure you've set the API key, as mentioned in pre-requisites above:

shell export API_KEY=xxxx

  • Ensure that your unit test report format is Cobertura(it's very common).
  • Generate tests using keploy-gen: bash keploy gen --sourceFilePath="<path to source code file>" --testFilePath="<path to existing unit test file>" --testCommand="<cmd to execute unit tests>" --coverageReportPath="<path to cobertura-coverage.xml>"

Configuration

Configure Keploy using command-line flags:

```bash

--sourceFilePath "" --testFilePath "" --coverageReportPath "coverage.xml" --testCommand "" --coverageFormat "cobertura" --expectedCoverage 100 --maxIterations 5 --testDir "" --llmBaseUrl "https://api.openai.com/v1" --model "gpt-4o" --llmApiVersion " ```

  • sourceFilePath: Path to the source file for which tests are to be generated.
  • testFilePath: Path where the generated tests will be saved.
  • coverageReportPath: Path to generate the coverage report.
  • testCommand (required): Command to execute tests and generate the coverage report.
  • coverageFormat: Type of the coverage report (default "cobertura").
  • expectedCoverage: Desired coverage percentage (default 100%).
  • maxIterations: Maximum number of iterations for refining tests (default 5).
  • testDir: Directory where tests will be written.
  • llmBaseUrl: Base url of the llm.
  • model: Specifies the AI model to use (default "gpt-4o").
  • llmApiVersion: API version of the llm if any (default "")

Frequently Asked Questions

  1. What is Keploy's Unit Test Generator (UTG)?

    • Keploy's UTG automates the creation of unit tests based on code semantics, enhancing test coverage and reliability.
  2. Does Keploy send your private data to any cloud server for test generation?

    • No, Keploy does not send any user code to remote systems, except when using the unit test generation feature. When using the UT gen feature, only the source code and the unit test code will be sent to the Large Language Model (LLM) you are using. By default, Keploy uses - litellm to support vast number of LLM backends. Yes, if your organization has its own LLM(a private one), you can use it with Keploy. This ensures that data is not sent to any external systems.
  3. How does Keploy contribute to improving unit test coverage?

    • By providing a zero code platform for automated testing, Keploy empowers developers to scale up their unit test coverage without extensive coding knowledge. This integration enhances testing reports, ultimately boosting confidence in the product's quality.
  4. Is Keploy cost-effective for automated unit testing?

    • Yes, Keploy optimizes costs by automating repetitive testing tasks and improving overall test efficiency.
  5. How does Keploy generate coverage reports?

    • Keploy generates detailed Cobertura format reports, offering insights into test effectiveness and code quality.
  6. Can Keploy handle large codebases efficiently?

    • Yes, Keploy is designed to handle large codebases efficiently, though processing time may vary based on project size and complexity.

🙋🏻‍♀️ Questions? 🙋🏻‍♂️

Reach out to us. We're here to answer!

Slack LinkedIn YouTube X

📝 Sample QuickStarts

🌐 Language Support

Go NodeJS

Other language may be supported, we've not tested them yet. If your coverage reports are of Cobertura format then you should be able to use keploy-gen in any language.

Dev Support

Keploy-gen is not just a project but an attempt to make developers life easier testing applications. It aims to simplify the creation and maintenance of tests, ensuring high coverage, and adapts to the complexity of modern software development.

Prompt Generation

Referred from Meta's research, the four primary prompts used in the deployment for the December 2023 Instagram and Facebook app test-a-thons

| Prompt Name | Template | | --------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | extendtest | Here is a Kotlin unit test class: {`existingtestclass`}. Write an extended version of the test class that includes additional tests to cover some extra corner cases. | | extendcoverage | Here is a Kotlin unit test class and the class that it tests: {existing_test_class} {class_under_test}. Write an extended version of the test class that includes additional unit tests that will increase the test coverage of the class under test. | | cornercases | Here is a Kotlin unit test class and the class that it tests: {`existingtestclass} {classundertest`}. Write an extended version of the test class that includes additional unit tests that will cover corner cases missed by the original and will increase the test coverage of the class under test. | | statementtocomplete | Here is a Kotlin class under test {`classundertest} This class under test can be tested with this Kotlin unit test class {existingtest_class`}. Here is an extended version of the unit test class that includes additional unit test cases that will cover methods, edge cases, corner cases, and other features of the class under test that were missed by the original unit test class: |

Limitation: This project currently doesn't generate quality fresh tests if there are no existing tests to learn from.

Enjoy coding with enhanced unit test coverage! 🫰

Owner

  • Name: Keploy Inc
  • Login: keploy
  • Kind: organization
  • Email: hello@keploy.io
  • Location: United States of America

Simple e2e testing for developers. Toolkit that creates test-cases and data mocks from API calls, DB queries, etc.

Citation (CITATION.cff)

cff-version: 1.2.0
title: 'Keploy: No code API testing platform. Create unit tests and data mocks from API calls.'
message: 'To cite Keploy in publications use:'
type: software
author: Keploy Inc
repository-code: 'https://github.com/keploy/keploy'
license: Apache License 2.0

Committers

Last synced: 9 months ago

All Time
  • Total Commits: 876
  • Total Committers: 91
  • Avg Commits per committer: 9.626
  • Development Distribution Score (DDS): 0.857
Past Year
  • Commits: 301
  • Committers: 39
  • Avg Commits per committer: 7.718
  • Development Distribution Score (DDS): 0.837
Top Committers
Name Email Commits
Shubham Jain s****n@o****m 125
Shivam Sourav Jha 6****a 97
Gourav kumar 4****x 94
Charan Kamarapu k****n@g****m 89
Ritik Jain 6****k 85
Sarthak Shyngle 5****0 64
Pranshu Srivastava 3****a 58
Akash Kumar 9****2 31
Animesh Pathak 5****o 27
Neha Gupta g****1@y****n 22
Yash Khare k****5@g****m 14
Ayush Sharma 8****0 14
Tejas Kumar 1****5 12
Sky Singh 1****4 11
Hermione Dadheech h****h@g****m 9
Asish Kumar 8****r 9
Felix-Ayush 6****4 8
Tushar d****e@p****m 5
Yashveer 1****r 5
Ahmed Lotfy 7****2 5
Govind Tomar 5****r 4
Nishant Bansal 1****3 4
aerowisca 1****a 3
Anjali Anupam 2****4@i****n 3
Yaten Dhingra 1****2 2
Shubh Gaur 9****a 2
Shotaro Yamasaki 8****n 2
Pradhyuman Sharma 9****a 2
Mohammed Mehdi 9****3 2
Madhav Sikka 3****a 2
and 61 more...
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 4 months ago

All Time
  • Total issues: 865
  • Total pull requests: 1,201
  • Average time to close issues: 2 months
  • Average time to close pull requests: 15 days
  • Total issue authors: 158
  • Total pull request authors: 148
  • Average comments per issue: 1.95
  • Average comments per pull request: 2.14
  • Merged pull requests: 607
  • Bot issues: 6
  • Bot pull requests: 28
Past Year
  • Issues: 282
  • Pull requests: 577
  • Average time to close issues: 13 days
  • Average time to close pull requests: 6 days
  • Issue authors: 89
  • Pull request authors: 91
  • Average comments per issue: 1.22
  • Average comments per pull request: 2.55
  • Merged pull requests: 297
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • shivamsouravjha (93)
  • slayerjain (91)
  • gouravkrosx (86)
  • Sonichigo (49)
  • khareyash05 (41)
  • Swpn0neel (36)
  • re-Tick (34)
  • charankamarapu (32)
  • nehagup (31)
  • Sarthak160 (25)
  • Hermione2408 (21)
  • AkashKumar7902 (15)
  • PranshuSrivastava (13)
  • Akash-Singh04 (13)
  • TvisharajiK (13)
Pull Request Authors
  • gouravkrosx (133)
  • shivamsouravjha (118)
  • charankamarapu (108)
  • Sarthak160 (80)
  • khareyash05 (52)
  • slayerjain (49)
  • ayush3160 (44)
  • AkashKumar7902 (38)
  • AhmedLotfy02 (33)
  • PranshuSrivastava (32)
  • Akash-Singh04 (31)
  • officialasishkumar (31)
  • re-Tick (29)
  • dependabot[bot] (23)
  • EraKin575 (19)
Top Labels
Issue Labels
Enhancement (380) keploy (339) bug (277) Good First Issue (165) Documentation (72) GSoC (66) docs (48) website (48) kROC (41) HACKTOBERFEST2024 (38) blog-website (37) nextjs (24) Go (20) level-2 (17) Help Wanted (16) level-3 (16) Repo/@Website (15) level-1 (14) Repo/@ui (13) Hacktoberfest (13) hacktoberfest2023 (11) api-fellowship (10) Repo/@docs (9) Repo/@samples-go (8) OSS (8) samples-go (8) samples-python (7) vscode-extension (6) dev-fellowship (6) completed-kroc (5)
Pull Request Labels
Dependencies (23) Go (12) github_actions (11) Don't Merge (5) Accepted (4) Enhancement (3) bug (3) hacktoberfest-accepted (2) keploy (2) Good First Issue (2) website (1) kROC (1) level-1 (1) sweep (1) Repo/@samples-go (1) samples-go (1)

Packages

  • Total packages: 4
  • Total downloads: unknown
  • Total dependent packages: 0
    (may contain duplicates)
  • Total dependent repositories: 0
    (may contain duplicates)
  • Total versions: 730
proxy.golang.org: github.com/keploy/Keploy
  • Versions: 81
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Dependent packages count: 5.3%
Average: 5.5%
Dependent repos count: 5.7%
Last synced: 4 months ago
proxy.golang.org: github.com/keploy/keploy/v2
  • Versions: 283
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Dependent packages count: 7.0%
Average: 7.5%
Dependent repos count: 7.9%
Last synced: 4 months ago
proxy.golang.org: go.keploy.io/server/v2

Package main is the entry point for the keploy application.

  • Versions: 285
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Dependent packages count: 7.5%
Average: 8.0%
Dependent repos count: 8.4%
Last synced: 4 months ago
proxy.golang.org: github.com/keploy/keploy
  • Versions: 81
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Dependent packages count: 7.0%
Average: 8.2%
Dependent repos count: 9.3%
Last synced: 4 months ago

Dependencies

.github/workflows/cla.yml actions
  • cla-assistant/github-action v2.1.3-beta composite
.github/workflows/codeql.yml actions
  • actions/checkout v3 composite
  • github/codeql-action/analyze v2 composite
  • github/codeql-action/autobuild v2 composite
  • github/codeql-action/init v2 composite
.github/workflows/docker-publish.yml actions
  • actions/checkout v2 composite
  • docker/build-push-action ad44023a93711e3deb337508980b4b5e9bcdc5dc composite
  • docker/login-action 28218f9b04b4f3f62068d7b6ce6ca5b26e35336c composite
  • docker/metadata-action 98669ae865ea3cffbcbaa878cf57c20bbf1c6c38 composite
  • docker/setup-buildx-action 79abd3f86f79a9d68a23c75a09a9a85889262adf composite
  • sigstore/cosign-installer 1e95c1de343b5b0c23352d6417ee3e48d5bcd422 composite
.github/workflows/go.yml actions
  • actions/checkout v2 composite
  • actions/setup-go v2 composite
  • codfish/semantic-release-action v1 composite
.github/workflows/greetings.yml actions
  • actions/first-interaction v1 composite
.github/workflows/main.yml actions
  • actions/checkout v2 composite
  • actions/setup-go v2 composite
.github/workflows/release.yml actions
  • Apple-Actions/import-codesign-certs v1 composite
  • actions/cache v3 composite
  • actions/checkout v2 composite
  • actions/setup-go v2 composite
  • actions/setup-node v3 composite
  • goreleaser/goreleaser-action v2 composite
Dockerfile docker
  • alpine latest build
  • golang alpine build
  • node 18-bullseye build
go.mod go
  • github.com/99designs/gqlgen v0.15.1
  • github.com/agnivade/levenshtein v1.1.1
  • github.com/araddon/dateparse v0.0.0-20210429162001-6b43995a97de
  • github.com/cpuguy83/go-md2man/v2 v2.0.1
  • github.com/creasty/defaults v1.6.0
  • github.com/fullstorydev/grpcurl v1.8.7
  • github.com/go-chi/chi v1.5.4
  • github.com/go-chi/cors v1.2.0
  • github.com/go-chi/render v1.0.1
  • github.com/go-playground/locales v0.14.0
  • github.com/go-playground/universal-translator v0.18.0
  • github.com/go-playground/validator/v10 v10.10.1
  • github.com/go-stack/stack v1.8.1
  • github.com/go-test/deep v1.0.8
  • github.com/golang/protobuf v1.5.2
  • github.com/golang/snappy v0.0.4
  • github.com/google/go-cmp v0.5.9
  • github.com/google/uuid v1.3.0
  • github.com/gorilla/websocket v1.4.2
  • github.com/hashicorp/golang-lru v0.5.4
  • github.com/jhump/protoreflect v1.14.0
  • github.com/k0kubun/pp/v3 v3.1.0
  • github.com/kelseyhightower/envconfig v1.4.0
  • github.com/keploy/go-sdk v0.7.9
  • github.com/klauspost/compress v1.15.1
  • github.com/leodido/go-urn v1.2.1
  • github.com/matryer/moq v0.2.5
  • github.com/mattn/go-colorable v0.1.12
  • github.com/mattn/go-isatty v0.0.14
  • github.com/mitchellh/mapstructure v1.4.3
  • github.com/pkg/errors v0.9.1
  • github.com/russross/blackfriday/v2 v2.1.0
  • github.com/soheilhy/cmux v0.1.5
  • github.com/stretchr/testify v1.7.1
  • github.com/tidwall/gjson v1.14.0
  • github.com/tidwall/match v1.1.1
  • github.com/tidwall/pretty v1.2.0
  • github.com/urfave/cli/v2 v2.3.0
  • github.com/vektah/gqlparser/v2 v2.2.0
  • github.com/wI2L/jsondiff v0.2.0
  • github.com/xdg-go/pbkdf2 v1.0.0
  • github.com/xdg-go/scram v1.1.0
  • github.com/xdg-go/stringprep v1.0.2
  • github.com/youmark/pkcs8 v0.0.0-20201027041543-1326539a0a0a
  • go.mongodb.org/mongo-driver v1.8.3
  • go.uber.org/atomic v1.9.0
  • go.uber.org/multierr v1.7.0
  • go.uber.org/zap v1.22.0
  • golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d
  • golang.org/x/mod v0.5.1
  • golang.org/x/net v0.0.0-20220225172249-27dd8689420f
  • golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
  • golang.org/x/sys v0.0.0-20220227234510-4e6760a101f9
  • golang.org/x/text v0.3.7
  • golang.org/x/tools v0.1.9
  • golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1
  • google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013
  • google.golang.org/grpc v1.48.0
  • google.golang.org/protobuf v1.28.1
  • gopkg.in/yaml.v2 v2.4.0
  • gopkg.in/yaml.v3 v3.0.1
go.sum go
  • 570 dependencies