Testing Approaches
Flow Testing
Flows are the core testable units in Genkit applications. You can test flows using:- Interactive Testing - Developer UI
- Command-Line Testing - CLI commands
- Automated Testing - Unit and integration tests
- Batch Testing - Testing with datasets
Interactive Testing with Developer UI
The Developer UI provides the fastest way to test flows during development:- Immediate visual feedback
- Trace inspection for debugging
- Easy input modification
- Streaming output support
- Open the Developer UI (typically
http://localhost:4000) - Navigate to the Flows section
- Select your flow (e.g.,
simpleGreeting) - Enter test input:
- Click “Run” and inspect the output
- Review the trace for detailed execution steps
Command-Line Testing
Running Individual Flows
Test flows from the command line with specific inputs:Batch Testing
Test flows with multiple inputs using batch runs: Create a test dataset (test-inputs.json):
Creating Testable Flows
Design flows with testing in mind:Self-Testing Flows
Create flows that test other flows:Evaluation-Based Testing
Evaluation goes beyond simple pass/fail testing by measuring quality metrics.Running Evaluations
Evaluate a flow with a dataset:Creating Test Datasets
Test datasets should include input, expected output, and context:Extracting Test Data from Traces
Generate test datasets from production traces:- Actual inputs used in production
- Outputs generated
- Context information
- Trace IDs for reference
Integration Testing
Test flows in integration with external services:Mock Testing
While Genkit doesn’t provide built-in mocking, you can implement mocks for testing:Unit Testing with Jest/Vitest
Write traditional unit tests for your flows:cloud-sql-pg/test/index.test.ts):
Best Practices
1. Use Clear Schemas
Define explicit input and output schemas for all flows:2. Test Edge Cases
- Empty inputs
- Very long inputs
- Special characters
- Invalid data types
- Missing required fields
3. Label Test Runs
Use labels to organize test traces:4. Maintain Test Datasets
Keep versioned test datasets in your repository:5. Automate Evaluation
Incorporate evaluation into CI/CD:6. Review Traces
Always inspect traces for failed tests to understand why they failed:- Run the test via CLI or UI
- Open the Developer UI
- Navigate to Traces
- Find the failed trace
- Inspect each step
7. Test with Real Data
Extract real usage patterns:Continuous Testing
Integrate testing into your development workflow:- During Development: Use Developer UI for immediate feedback
- Before Commits: Run batch tests locally
- In CI/CD: Run automated evaluations
- After Deployment: Extract production data for new test cases
Next Steps
- Learn about Debugging techniques for troubleshooting
- Explore the Developer UI for interactive testing
- Review CLI commands for test automation