Skip to content

Commit ae5e1c9

Browse files
committed
chore: test commit/remove utg cli
Signed-off-by: amaan-bhati <amaanbhati49@gmail.com>
1 parent 7bd8285 commit ae5e1c9

File tree

1 file changed

+0
-129
lines changed

1 file changed

+0
-129
lines changed

versioned_docs/version-2.0.0/running-keploy/unit-test-generator.md

Lines changed: 0 additions & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -106,135 +106,6 @@ Generate unit tests with a single click directly from your IDE.
106106
- All test files and test cases are generated instantly for your entire project
107107
- Tests are created with comprehensive coverage for your codebase
108108

109-
## 3. Command Line Interface 💻
110-
111-
The traditional method using Keploy CLI commands for automated test generation.
112-
113-
**Prerequisites:**
114-
`API KEY` of the AI model is needed, this can be from either of one these:
115-
116-
- **OpenAI's [GPT-4o](https://platform.openai.com/) [preferred].**
117-
- Alternative LLMs via [litellm](https://github.com/BerriAI/litellm?tab=readme-ov-file#quick-start-proxy---cli).
118-
- [Azure OpenAI](https://azure.microsoft.com/en-in/products/ai-services/openai-service) Services
119-
120-
Now, let's setup the `API_KEY` as environment variable:
121-
122-
```bash
123-
export API_KEY=xxxx
124-
```
125-
126-
**Usage:**
127-
128-
```bash
129-
keploy gen [flag]
130-
```
131-
132-
## Command Line Usage Guide
133-
134-
### Running with Javascript/TypeScript applications
135-
136-
For the we need to make sure that the coverage report is in coberuta format, so to make sure let's modify our `package.json` by adding:
137-
138-
```json
139-
"jest": {
140-
"coverageReporters": ["text", "cobertura"],
141-
}
142-
```
143-
144-
or if `jest.config.js` is present then, we need to add:
145-
146-
```js
147-
module.exports = {
148-
coverageReporters: ["text", "cobertura"],
149-
};
150-
```
151-
152-
#### Generating Unit Tests
153-
154-
You can test a smaller section of application or to control costs, we can consider generating tests for a single source and its corresponding test file:
155-
156-
```bash
157-
keploy gen --source-file-path="<path to source file>" \
158-
--test-file-path="<path to test file for above source file>" \
159-
--test-command="npm test" \
160-
--coverage-report-path="<path to coverage.xml>"
161-
```
162-
163-
For Entire Application we can generate tests by using `--test-dir` instead of `--test-file-path`.
164-
165-
> ⚠️ Warning: Executing command with `--test-dir` 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.
166-
167-
#### Example
168-
169-
Let us consider the [express-mongoose](https://github.com/keploy/samples-typescript/tree/main/express-mongoose) sample-application, where we have a jest testcases under `test` folder with name `routes.test.js`.
170-
171-
We have modified our `package.json` by adding below:
172-
173-
```json
174-
"jest": {
175-
"collectCoverage": true,
176-
"coverageReporters": ["text", "cobertura"],
177-
"coverageDirectory": "./coverage"
178-
}
179-
```
180-
181-
Now let's run Keploy UTG command:
182-
183-
```bash
184-
keploy gen \
185-
--source-file-path="./src/routes/routes.js" \
186-
--test-file-path="./test/routes.test.js" \
187-
--test-command="npm test" \
188-
--coverage-report-path="./coverage/cobertura-coverage.xml"
189-
```
190-
191-
We will get following output:
192-
193-
<img src="/docs/img/express-mongoose-utg.png" alt="Keploy test coverage with ai generated unit tests for express-mongoose" width="100%" style={{ borderRadius: '5px' }}/>
194-
195-
_Voila!! The Generated Testcases have provided with 58% coverage🌟_
196-
197-
### Running with Golang applications
198-
199-
To ensure Cobertura formatted coverage reports, we need to install the following:
200-
201-
```bash
202-
go install github.com/axw/gocov/gocov@v1.1.0
203-
go install github.com/AlekSi/gocov-xml@v1.1.0
204-
```
205-
206-
#### Generating Unit Tests
207-
208-
With the above dependecies installed, we can now generate tests for our application by the following dommand:
209-
210-
```bash
211-
keploy gen --source-file-path="<path to source file>o" \
212-
--test-file-path="<path to test file for above source file>" \
213-
--test-command="go test -v ./... -coverprofile=coverage.out && gocov convert coverage.out | gocov-xml > coverage.xml" \
214-
--coverage-report-path="<path to coverage.xml>"
215-
```
216-
217-
For Entire Application we can generate tests by using `--test-dir` instead of `--test-file-path`.
218-
219-
> ⚠️ Warning: Executing command with `--test-dir` 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.
220-
221-
#### Example
222-
223-
Let us consider the [mux-sql](https://github.com/keploy/samples-go/tree/main/mux-sql/) sample-application, where we already have our `app_test.go` test file for `app.go` source file:
224-
225-
```bash
226-
keploy gen --source-file-path="app.go" \
227-
--test-file-path="app_test.go" \
228-
--test-command="go test -v ./... -coverprofile=coverage.out && gocov convert coverage.out | gocov-xml > coverage.xml" \
229-
--coverage-report-path="./coverage.xml"
230-
```
231-
232-
We will get following output:
233-
234-
<img src="/docs/img/mux-sql-utg.png" alt="Keploy test coverage with ai generated unit test for mux-sql" width="100%" style={{ borderRadius: '5px' }}/>
235-
236-
_Voila!! The Generated Testcases have provided with 71% coverage in just 2 iterations 🌟_
237-
238109
## Frequently Asked Questions(FAQs)
239110

240111
1. **What is Keploy's Unit Test Generator (UTG)?**<br/>

0 commit comments

Comments
 (0)