Cloving Generate Unit Tests Command Documentation

Learn how to use the cloving generate unit-tests command to generate unit tests for your project.

Usage

cloving generate unit-tests [options]

Description

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.

Options

This command accepts the following options:

  • -s, --silent: Run the command without asking for confirmation of submitting prompts.
  • -f, --files <filenames...>: Specify filenames for the unit tests.
  • -m, --model <model>: Select the model to use (e.g., openai, claude, ollama, ollama:llama3, claude:claude-3-5-sonnet-20240620).

Interactive Prompts

The cloving generate unit-tests command uses the following interactive prompts:

  • Action selection: Prompt to select an action to perform with the generated unit tests (e.g., save, copy to clipboard, done).
  • File selection: Prompt to select specific unit test files to save or copy to the clipboard.

Example Process

Example Unit Test Generation Session

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.