Learn how to use the cloving generate unit-tests
command to generate unit tests for your project.
cloving generate unit-tests [options]
The cloving generate unit-tests
command helps you generate unit tests for your project files. It uses the AI APIs configured with cloving config
as well as the cloving.json file created by cloving init
to analyze the input and generate relevant unit tests, which can then be reviewed, revised, or saved.
This command accepts the following options:
The cloving generate unit-tests
command uses the following interactive prompts:
Here is an example of what a unit test generation session might look like:
$ cloving generate unit-tests -f src/utils/config_utils.ts src/utils/git_utils.ts
Generating unit tests...
Generated unit tests:
```typescript
// src/utils/config_utils.test.ts
import { getConfig, saveConfig } from './config_utils'
describe('config_utils', () => {
test('getConfig returns default config if none exists', () => {
const config = getConfig()
expect(config).toEqual({})
})
test('saveConfig saves the config correctly', () => {
const config = { key: 'value' }
saveConfig(config)
const savedConfig = getConfig()
expect(savedConfig).toEqual(config)
})
})
// src/utils/git_utils.test.ts
import { getGitDiff } from './git_utils'
describe('git_utils', () => {
test('getGitDiff returns the correct diff', () => {
const diff = getGitDiff()
expect(diff).toContain('diff --git')
})
})
```
What would you like to do?
1. Save a Unit Test File
2. Save All Unit Test Files
3. Copy Unit Test to Clipboard
4. Copy Entire Response to Clipboard
5. Done
If you choose to save the unit tests, the process continues as follows:
$ cloving generate unit-tests -f src/utils/config_utils.ts src/utils/git_utils.ts
Generating unit tests...
Generated unit tests:
```typescript
// src/utils/config_utils.test.ts
import { getConfig, saveConfig } from './config_utils'
describe('config_utils', () => {
test('getConfig returns default config if none exists', () => {
const config = getConfig()
expect(config).toEqual({})
})
test('saveConfig saves the config correctly', () => {
const config = { key: 'value' }
saveConfig(config)
const savedConfig = getConfig()
expect(savedConfig).toEqual(config)
})
})
// src/utils/git_utils.test.ts
import { getGitDiff } from './git_utils'
describe('git_utils', () => {
test('getGitDiff returns the correct diff', () => {
const diff = getGitDiff()
expect(diff).toContain('diff --git')
})
})
```
What would you like to do?
1. Save a Unit Test File
2. Save All Unit Test Files
3. Copy Unit Test to Clipboard
4. Copy Entire Response to Clipboard
5. Done
> 1
Which unit test file do you want to save?
1. src/utils/config_utils.test.ts
2. src/utils/git_utils.test.ts
> 1
src/utils/config_utils.test.ts has been saved.