Test Generation
Auto-generate comprehensive unit tests for your code changes using AI.
Introduction
The Test Generation feature uses AI to analyze your code and generate appropriate test cases. It works with your existing test framework, follows your project's patterns, and covers happy paths, edge cases, and error handling.
Key Features
- Framework Detection — Automatically detects PHPUnit, Pest, Jest, pytest, and more
- Pattern Matching — Follows your existing test conventions
- Comprehensive Coverage — Happy path, edge cases, and error handling
- One-Click Apply — Apply generated tests directly to your codebase
- Multi-Platform — Available via slash command, CLI, and VS Code
Using the Slash Command
The quickest way to generate tests is via the /revio test slash command on a pull request.
Basic Usage
Comment on any PR to generate tests for the changed code:
@revio test
Jasper will analyze all changed files in the PR and generate appropriate tests.
Targeting Specific Code
You can focus test generation on specific files or functions:
@revio test UserController
@revio test src/Services/PaymentService.php
Generated Output
Jasper posts the generated tests as a comment with:
- Test file path
- List of generated test cases
- Full test code with syntax highlighting
- Apply button to commit the tests
CLI Usage
Generate tests locally using the Revio CLI.
Installation
npm install -g @revio/cli
Basic Commands
| Command | Description |
|---|---|
revio test |
Generate tests for staged changes |
revio test --all |
Generate tests for all uncommitted changes |
revio test --file path/to/file.php |
Generate tests for a specific file |
revio test --function methodName |
Generate tests for a specific function |
Options
| Option | Description |
|---|---|
--framework <name> |
Override framework detection |
--format <type> |
Output format: table, json, markdown |
--apply |
Apply tests directly to filesystem |
--dry-run |
Preview without writing files |
--include-patterns |
Analyze existing tests for patterns |
Example Output
$ revio test --file src/Services/UserService.php
Generated 8 tests
tests/Unit/Services/UserServiceTest.php (NEW)
+------------------------------------------+--------+----------+
| Test Case | Type | Coverage |
+------------------------------------------+--------+----------+
| test_create_user_with_valid_data | Happy | create() |
| test_create_user_with_empty_email | Edge | create() |
| test_create_user_with_invalid_email | Error | create() |
| test_create_user_hashes_password | Happy | create() |
| test_find_user_by_id_returns_user | Happy | find() |
| test_find_user_by_id_returns_null | Edge | find() |
| test_update_user_validates_fields | Error | update() |
| test_delete_user_soft_deletes | Happy | delete() |
+------------------------------------------+--------+----------+
Framework: Pest (detected from composer.json)
Run with --apply to write test files
VS Code Integration
Generate tests directly from VS Code using the Revio extension.
Commands
| Command | Keybinding | Description |
|---|---|---|
| Revio: Generate Tests | Cmd+Shift+T | Generate tests for current file |
| Revio: Generate Tests for Selection | — | Generate tests for selected code |
| Revio: Generate Tests for Function | — | Generate tests for function at cursor |
Context Menu
Right-click in the editor to access test generation:
- Revio: Generate Tests for File
- Revio: Generate Tests for Function
- Revio: Generate Tests for Selection
Preview Panel
Generated tests appear in a preview panel where you can:
- Review individual test cases
- View the full test code
- Apply all tests to your workspace
- Copy code to clipboard
Supported Frameworks
Test generation supports major testing frameworks across popular languages:
| Language | Framework | File Pattern |
|---|---|---|
| PHP | PHPUnit | tests/*Test.php |
| PHP | Pest | tests/*.php |
| JavaScript | Jest | *.test.js, __tests__/*.js |
| TypeScript | Jest/Vitest | *.test.ts, *.spec.ts |
| Python | pytest | test_*.py, *_test.py |
| Go | testing | *_test.go |
| Ruby | RSpec | *_spec.rb |
| Ruby | Minitest | *_test.rb |
Test Coverage Types
Generated tests cover multiple scenarios:
Happy Path
Tests for normal, successful execution:
- Valid inputs produce expected outputs
- State changes occur correctly
- Return values match expectations
Edge Cases
Tests for boundary conditions:
- Empty inputs (empty strings, arrays, null)
- Boundary values (zero, max int, min int)
- Special characters and encoding
- Large inputs
Error Cases
Tests for error handling:
- Invalid input validation
- Exception throwing
- Error state handling
- Authorization failures
Mock Verification
Tests for dependency interactions:
- External service calls
- Database operations
- API interactions
- Event dispatching
Framework Detection
Jasper automatically detects your test framework by analyzing:
composer.jsonfor PHP (PHPUnit, Pest)package.jsonfor JS/TS (Jest, Vitest, Mocha)requirements.txtfor Python (pytest)go.modfor GoGemfilefor Ruby (RSpec, Minitest)- Existing test file patterns in your project
Pattern Analysis
When generating tests, Jasper analyzes your existing tests to match:
- Naming Conventions —
test_*,it_*, or descriptive names - Structure — Class-based or function-based tests
- Assertions — Your preferred assertion style
- Setup/Teardown — Fixtures and before/after hooks
- Mocking — Mock library and patterns
Tip: Use the --include-patterns flag to ensure generated tests
closely match your project's existing style.
Applying Generated Tests
Via Slash Command
Click the Apply button on the generated test comment. Jasper will commit the test files directly to your PR branch.
Via CLI
revio test --apply
This writes the test files to your local filesystem.
Via VS Code
Click Apply All Tests in the preview panel to write files to your workspace.
Configuration
Repository Settings
Configure test generation per repository in Repository Settings → Test Generation:
| Setting | Description |
|---|---|
| Framework | Override auto-detected framework |
| Test Directory | Custom test directory path |
| Exclude Patterns | Files to skip during generation |
| Custom Instructions | Additional context for AI |
VS Code Settings
{
"revio.testGeneration.enabled": true,
"revio.testGeneration.framework": "auto",
"revio.testGeneration.includeEdgeCases": true,
"revio.testGeneration.includeErrorCases": true,
"revio.testGeneration.includeMocks": true,
"revio.testGeneration.autoApply": false
}
Best Practices
- Review Generated Tests — Always review tests before committing; AI may miss domain-specific logic
- Run Tests Locally — Verify generated tests pass before pushing
- Use Existing Patterns — Enable pattern analysis for consistent test style
- Add Custom Instructions — Provide context about your domain or conventions
- Target Specific Code — Generate tests for specific files/functions for better results
Note: Generated tests are a starting point. Human review is recommended, especially for complex business logic where AI may not fully understand the requirements.
Troubleshooting
Wrong Framework Detected
If the wrong framework is detected:
- Use
--frameworkflag to override - Configure framework in repository settings
- Ensure package files have correct dependencies
Tests Don't Match Project Style
- Enable
--include-patternsfor pattern analysis - Add custom instructions in repository settings
- Provide more existing tests as examples
Tests Fail to Run
- Check imports and namespaces are correct
- Verify mock dependencies are available
- Ensure test directory is correct
Need help? Check the slash commands documentation or general troubleshooting guide.