|
| 1 | +--- |
| 2 | +title: Generate Unit Tests |
| 3 | +description: Automated Unit Test Generation with CodeRabbit |
| 4 | +--- |
| 5 | + |
| 6 | +```mdx-code-block |
| 7 | +import ProPlanNotice from '@site/src/components/ProPlanNotice.mdx'; |
| 8 | +
|
| 9 | +<ProPlanNotice /> |
| 10 | +``` |
| 11 | + |
| 12 | +# Unit Test Generation |
| 13 | + |
| 14 | +Unit Test Generation is part of the [finishing touches](/future-development#finishing-touches). |
| 15 | + |
| 16 | +Unit Test Generation is an Early Access feature. |
| 17 | + |
| 18 | +## Usage |
| 19 | + |
| 20 | +Once you are done with your pull request and its reviews, you may want to perform finishing touches to your code, such as adding unit tests. You can request CodeRabbit to generate unit tests by typing `@coderabbitai auto-generate unit tests` in a comment under that pull request or by clicking a checkbox under `🧪 Generate Unit Tests` in the CodeRabbit Walkthrough. |
| 21 | + |
| 22 | +Once sent, CodeRabbit will perform the following actions: |
| 23 | + |
| 24 | +- The CodeRabbit agent will examine your code for places where it needs tests |
| 25 | +- Unit tests will be generated for the PR, in a separate PR, in the same PR in a new commit, or in a comment to copy-paste, depending on your choice |
| 26 | +- If (and only if) you choose to generate the unit tests in a separate PR, CodeRabbit will examine your GitHub checks (build steps and tests and such) and adjust the PR to deal with build failures, test failures and similar. |
| 27 | + |
| 28 | +Here's an example of what a pull request may look like: |
| 29 | + |
| 30 | + |
| 31 | + |
| 32 | +## Path Instructions |
| 33 | + |
| 34 | +You can customize the generated unit tests by providing instructions based on file paths in your `.coderabbit.yaml`. The `path` is a [minimatch](https://github.com/isaacs/minimatch) pattern. |
| 35 | + |
| 36 | +```yaml |
| 37 | +code_generation: |
| 38 | + unit_tests: |
| 39 | + path_instructions: |
| 40 | + - path: "**/*.ts" |
| 41 | + instructions: | |
| 42 | + Use vitest for testing framework. |
| 43 | + Generate comprehensive test cases including edge cases and error conditions. |
| 44 | + Do not omit the imports; the test file must be valid. |
| 45 | +``` |
| 46 | +
|
| 47 | +## Supported software forges |
| 48 | +
|
| 49 | +These software forges are supported: |
| 50 | +
|
| 51 | +- GitHub |
| 52 | +
|
| 53 | +We are working on GitLab and Azure DevOps support as of writing. |
| 54 | +
|
| 55 | +## Supported CI/CD systems |
| 56 | +
|
| 57 | +These CI/CD systems are supported for post-generation adjustments: |
| 58 | +
|
| 59 | +- GitHub actions |
| 60 | +
|
| 61 | +We are working on CircleCI and Travis CI support as of writing. |
| 62 | +
|
| 63 | +## Supported languages |
| 64 | +
|
| 65 | +Any programming language and unit test library / framework known to the LLM is supported. |
0 commit comments