Generate your Tests
Generate AI-powered tests from your codebase with bugster generate
The bugster generate
command analyzes your codebase and automatically creates comprehensive test specifications. It understands your application structure and generates relevant test cases for your pages and components.
You must run bugster init
before using the generate command. The command requires your project to be properly configured and authenticated.
Basic Usage
This command will:
- Analyze your codebase structure and components
- Generate test specifications for all detected pages
- Save test files to
.bugster/tests/
directory - Organize tests by feature/page folders
How It Works
Codebase Analysis
Bugster scans your Next.js project to understand:
- Page structure (App Router or Pages Router)
- Component dependencies and imports
- Authentication requirements
- Form elements and user interactions
AI Test Generation
Using the codebase analysis, AI creates:
- Realistic user scenarios and workflows
- Test steps that match your UI components
- Expected outcomes for each interaction
- Context-aware test cases based on page functionality
Test Organization
Generated tests are saved as:
- YAML files with clear, readable test specifications
- Organized in folders matching your page structure
- Numbered for execution order (1_login.yaml, 2_signup.yaml)
Command Flags and Options
Specific Page Generation
Generate tests only for the selected pages in your application.
--page
--page
Purpose: Generate tests only for specific page files
Format: Comma-separated list of relative file paths
Path types:
- Relative paths:
pages/auth.tsx
- Absolute paths:
/full/path/to/pages/auth.tsx
(converted to relative)
Validation:
- Files must exist
- Must be JavaScript/TypeScript files (.js, .jsx, .ts, .tsx)
- Must be actual files, not directories
Examples:
Test Count Generation
Generate a certain amount of tests.
--count
--count
Purpose: Control the number of test specs generated per page
Range: 1 to 30 tests per page
Default: Automatically determined based on page complexity
Use cases:
--count 1
: Quick smoke tests for each page--count 5
: Comprehensive testing for critical pages--count 10+
: Extensive testing for complex workflows
Examples:
Combined Usage Examples
Development Workflow
Generated Test Structure
After running bugster generate
, your project structure will include:
Test File Format
Each generated test file contains:
Understanding Test Generation
Page Detection
Bugster automatically detects pages based on:
Pages Router
Detection: Files in pages/
directory
Examples:
pages/index.tsx
→/
pages/about.tsx
→/about
pages/user/[id].tsx
→/user/:id
Excludes: API routes, _app.tsx
, _document.tsx
App Router
Detection: page.tsx
files in app/
directory
Examples:
app/page.tsx
→/
app/about/page.tsx
→/about
app/user/[id]/page.tsx
→/user/:id
Excludes: layout.tsx
, loading.tsx
, API routes
Test Context Generation
AI considers multiple factors when generating tests:
Component Analysis
Component Analysis
Form elements: Login forms, contact forms, checkout flows
Interactive elements: Buttons, links, modals, dropdowns
Navigation: Menu items, breadcrumbs, pagination
Data display: Tables, lists, cards, charts
User Workflows
User Workflows
Authentication flows: Login, signup, logout, password reset
CRUD operations: Create, read, update, delete actions
E-commerce flows: Add to cart, checkout, payment
Search and filtering: Search bars, filters, sorting
Existing Tests Context
Existing Tests Context
Duplicate prevention: Avoids creating similar tests
Coverage gaps: Identifies untested scenarios
Test relationships: Understands dependencies between tests
Consistency: Maintains similar testing patterns
Generation Status and Progress
During generation, you’ll see progress updates:
Generation Time
- Small projects (5-10 pages): 30-60 seconds
- Medium projects (10-25 pages): 1-3 minutes
- Large projects (25+ pages): 3-5 minutes
Best Practices
Selective Generation
Use —page flag for specific feature testing
Focus on critical paths when time is limited
Generate incrementally for new features
Combine with existing tests rather than full regeneration
Test Quality
Review generated tests before committing
Customize for your workflows if needed
Ensure credential alignment with your test users
Validate test coverage matches your requirements
Troubleshooting
No tests generated
No tests generated
Possible causes:
- Not in a Next.js project directory
- No detectable pages in your project
- Network connectivity issues
Solutions:
- Verify you’re in the correct project directory
- Check that you have pages in
pages/
orapp/
directories - Use
--show-logs
to see detailed analysis output
Generation timeout
Generation timeout
Error: Test generation timeout after 3 minutes
Solutions:
- Try again (temporary service issue)
- Use
--page
flag to generate for specific pages - Contact support if issue persists
Invalid page paths
Invalid page paths
Error: File not found or invalid file type
Solutions:
- Verify file paths are correct and relative to project root
- Ensure files have .js, .jsx, .ts, or .tsx extensions
- Check that files exist and are readable
Generation failed
Generation failed
Error: Test generation failed during processing
Solutions:
- Check network connectivity
- Verify API key is valid
- Try with
--force
flag - Use
--show-logs
for detailed error information
Next Steps
After generating tests, you can: