Skip to content

Commit

Permalink
docs: add unit-gen docs (#1971)
Browse files Browse the repository at this point in the history
Signed-off-by: Neha Gupta <gneha21@yahoo.in>
  • Loading branch information
nehagup committed Jun 14, 2024
1 parent 0830421 commit 2cf521e
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 26 deletions.
60 changes: 35 additions & 25 deletions pkg/service/utgen/README.md → README-UnitGen.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,37 +60,41 @@ Referred from [Meta's research](https://arxiv.org/pdf/2402.09171), TestGen-LLM t

## Prerequisites

**AI model Setup** - Set the environment variable **export API_KEY=xxxx**, apiKey can be from either of one these:
**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](https://github.com/BerriAI/litellm?tab=readme-ov-file#quick-start-proxy---cli).

- Azure OpenAI.
- Azure OpenAI

## Installation

Install Keploy-gen locally by running the following command:
Install Keploy locally by running the following command:

#### Linux/Mac
#### Linux/Mac

```shell
curl -O https://raw.githubusercontent.com/keploy/keploy/main/keploy.sh && source keploy.sh
curl --silent -O -L https://keploy.io/install.sh && source install.sh
```

#### Windows
#### Windows

- [Download](https://github.com/keploy/keploy/releases/latest/download/keploy_windows_amd64.tar.gz) and move the keploy.exe file to C:\Windows\System32
- [Download](https://github.com/keploy/keploy/releases/latest/download/keploy_windows_amd64.tar.gz) and **move the keploy.exe file** to `C:\Windows\System32`

### ![NodeJS](https://img.shields.io/badge/node.js-6DA55F?style=for-the-badge&logo=node.js&logoColor=white) Running with Node.js/TypeScript applications
### ![NodeJS](https://img.shields.io/badge/node.js-6DA55F?style=for-the-badge&logo=node.js&logoColor=white) Running with Node.js/TypeScript applications

- Set the API key, as mentioned in pre-requisites above:
- 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`:
- Ensure **Cobertura** formatted coverage reports, edit `jest.config.js` or `package.json`:
<br/>

```json
Expand All @@ -99,17 +103,18 @@ curl -O https://raw.githubusercontent.com/keploy/keploy/main/keploy.sh && source
"coverageReporters": ["text", "cobertura"],
}
```
or

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

### Usage
#### Generating Unit Tests

- **Generate tests using Keploy:**
- Run the following command in the root of your application.
<br/>

- **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:
Expand All @@ -128,23 +133,23 @@ curl -O https://raw.githubusercontent.com/keploy/keploy/main/keploy.sh && source
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! 🫰
🎉 You should see improved test cases and code-coverage. ✅ Enjoy coding with enhanced unit test coverage! 🫰

### ![Go](https://img.shields.io/badge/go-%2300ADD8.svg?style=for-the-badge&logo=go&logoColor=white) → Running with Golang applications

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

```shell
export API_KEY=xxxx
```

- Ensure Cobertura formatted coverage reports.
- 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
```
### Usage
- **Generate tests using Keploy:**
#### Generating Unit Tests
- Run the following command in the root of your application.
<br/>

- **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:
Expand All @@ -167,14 +172,14 @@ curl -O https://raw.githubusercontent.com/keploy/keploy/main/keploy.sh && source

### → Setup for Other Languages

- Set the API key, as mentioned in pre-requisites above:
- 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:
- 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>"
```
Expand Down Expand Up @@ -219,6 +224,11 @@ Reach out to us. We're here to answer!
[![YouTube](https://img.shields.io/badge/YouTube-%23FF0000.svg?style=for-the-badge&logo=YouTube&logoColor=white)](https://www.youtube.com/channel/UC6OTg7F4o0WkmNtSoob34lg)
[![Twitter](https://img.shields.io/badge/Twitter-%231DA1F2.svg?style=for-the-badge&logo=Twitter&logoColor=white)](https://twitter.com/Keployio)
# 📝 Sample QuickStarts
- ![Go](https://img.shields.io/badge/go-%2300ADD8.svg?style=for-the-badge&logo=go&logoColor=white) : Try a unit-gen on [Mux-SQL](https://github.com/keploy/samples-go/tree/main/mux-sql#create-unit-testcase-with-keploy) app
## 🌐 Language Support
![Go](https://img.shields.io/badge/go-%2300ADD8.svg?style=for-the-badge&logo=go&logoColor=white)
Expand Down
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,23 @@ Keploy not only records API calls, but also records database calls and replays t

> 🐰 **Fun fact:** Keploy uses itself for testing! Check out our swanky coverage badge: [![Coverage Status](https://coveralls.io/repos/github/keploy/keploy/badge.svg?branch=main&kill_cache=1)](https://coveralls.io/github/keploy/keploy?branch=main&kill_cache=1) &nbsp;
## 🚨 Here for [Unit Test Generator](README-UnitGen.md) (ut-gen)?
Keploy's new launched world's first unit test generator(ut-gen) implementation of [Meta LLM research paper](https://arxiv.org/pdf/2402.09171), it understands code semantics and generates meaningful unit tests, aiming to:

- **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.

### 📜 Follow [Unit Test Generator README](README-UnitGen.md)! ✅

## 📘 Documentation!
Become a Keploy pro with **[Keploy Documentation](https://keploy.io/docs/)**.

<img src="https://raw.githubusercontent.com/keploy/docs/main/static/gif/record-replay.gif" width="100%" alt="Record Replay Testing"/>

# 🚀 Quick Installation
# 🚀 Quick Installation (API test generator)

Integrate Keploy by installing the agent locally. No code-changes required.

Expand Down

0 comments on commit 2cf521e

Please sign in to comment.