Skip to main content
Testing AI applications requires different strategies than traditional software testing. Genkit provides tools and patterns for testing flows, evaluating model outputs, and ensuring your AI features work reliably.

Testing Approaches

Flow Testing

Flows are the core testable units in Genkit applications. You can test flows using:
  1. Interactive Testing - Developer UI
  2. Command-Line Testing - CLI commands
  3. Automated Testing - Unit and integration tests
  4. Batch Testing - Testing with datasets

Interactive Testing with Developer UI

The Developer UI provides the fastest way to test flows during development:
Benefits:
  • Immediate visual feedback
  • Trace inspection for debugging
  • Easy input modification
  • Streaming output support
Example Workflow:
  1. Open the Developer UI (typically http://localhost:4000)
  2. Navigate to the Flows section
  3. Select your flow (e.g., simpleGreeting)
  4. Enter test input:
  5. Click “Run” and inspect the output
  6. Review the trace for detailed execution steps

Command-Line Testing

Running Individual Flows

Test flows from the command line with specific inputs:
With Output Streaming:
Saving Results:

Batch Testing

Test flows with multiple inputs using batch runs: Create a test dataset (test-inputs.json):
Run the batch test:
Label batch runs for tracking:
This creates labeled traces that can be filtered in the Developer UI and extracted later for evaluation.

Creating Testable Flows

Design flows with testing in mind:
Testing this flow:

Self-Testing Flows

Create flows that test other flows:
Run the test flow:
View the trace in the Developer UI to see the results of all nested flow executions.

Evaluation-Based Testing

Evaluation goes beyond simple pass/fail testing by measuring quality metrics.

Running Evaluations

Evaluate a flow with a dataset:
Evaluate a standalone dataset:

Creating Test Datasets

Test datasets should include input, expected output, and context:

Extracting Test Data from Traces

Generate test datasets from production traces:
This extracts:
  • Actual inputs used in production
  • Outputs generated
  • Context information
  • Trace IDs for reference
Extract data from labeled runs:

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:
Example from Genkit source (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:
  1. Run the test via CLI or UI
  2. Open the Developer UI
  3. Navigate to Traces
  4. Find the failed trace
  5. Inspect each step

7. Test with Real Data

Extract real usage patterns:
Use this data to create realistic test cases.

Continuous Testing

Integrate testing into your development workflow:
  1. During Development: Use Developer UI for immediate feedback
  2. Before Commits: Run batch tests locally
  3. In CI/CD: Run automated evaluations
  4. After Deployment: Extract production data for new test cases

Next Steps