Scenario-Based Generation
Generate tests from business scenarios
Scenario-based generation creates tests from business requirements and user workflows, either AI-detected from your API or manually defined.
Overview
Scenario-based generation focuses on what to test rather than how to test it. You describe business scenarios, and AI figures out which APIs to call and how to validate the behavior.
Two Approaches
AI-Detected Scenarios
AI analyzes your OpenAPI document and automatically identifies common business scenarios:
- User registration and authentication flows
- CRUD lifecycles
- Multi-step workflows
- Error handling patterns
Manual Scenarios
You describe what to test in natural language:
- Business requirements
- User stories
- Integration workflows
- Custom test cases
AI-Detected Scenarios
How It Works
1. Analyze API Document
AI examines your OpenAPI specification:
- Identifies endpoint relationships
- Detects common patterns (CRUD, auth, etc.)
- Groups related operations
- Suggests business scenarios
2. Generate Scenario List
Project → Test Cases → Detect Scenarios
AI presents detected scenarios:
Example Scenarios:
✅ User Registration and Login Flow
APIs: POST /auth/register, POST /auth/login, GET /users/me
✅ Complete Pet Management Lifecycle
APIs: POST /pets, GET /pets/{id}, PUT /pets/{id}, DELETE /pets/{id}
✅ Order Processing Workflow
APIs: POST /cart/items, POST /orders, POST /payments, GET /orders/{id}
✅ Error Handling: Invalid User Input
APIs: POST /users (various invalid inputs)
3. Select and Generate
- Review suggested scenarios
- Select ones to test
- Click “Generate Tests”
- AI creates executable code
Scenario Types Detected
Authentication Flows:
- User registration → email verification → login
- Login → access protected resource → logout
- Password reset flow
- Token refresh flow
CRUD Lifecycles:
- Create → Read → Update → Delete
- Create → List → Filter → Sort
- Bulk operations
Business Workflows:
- Shopping cart → checkout → payment → confirmation
- Content creation → review → publish
- Multi-step approval processes
Error Scenarios:
- Validation errors (400)
- Authentication errors (401)
- Authorization errors (403)
- Not found errors (404)
- Conflict errors (409)
Manual Scenarios
How It Works
1. Describe Scenario
Project → Test Cases → Define Scenario
Write what you want to test in plain English:
Simple Example:
Test that a new user can register with valid data
and the user appears in the user list.
Complex Example:
Test the complete order workflow:
1. User adds items to cart
2. User applies discount code
3. User proceeds to checkout
4. User makes payment
5. Order confirmation is received
Business Logic Example:
Test that applying a 10% discount code reduces
the order total correctly and the discount is
reflected in the order confirmation.
2. AI Analysis
AI processes your description:
- Identifies relevant APIs
- Plans test flow
- Determines validations
- Suggests test data
3. Review and Generate
- Review AI’s plan
- Adjust if needed
- Generate executable code
Writing Effective Scenarios
Be Specific:
✅ Test that creating a pet with valid data returns 201
and the pet can be retrieved with GET /pets/{id}
❌ Test pet creation
Include Expected Behavior:
✅ Test that registering with an existing email
returns 409 Conflict error
❌ Test user registration with existing email
Describe the Flow:
✅ Test complete authentication flow:
- Register new user
- Verify email
- Login with credentials
- Access protected resource
❌ Test authentication
Mention Important Details:
✅ Test that password must be at least 8 characters
and contain uppercase, lowercase, and numbers
❌ Test password validation
Use Cases
Business Logic Testing
Test complex workflows spanning multiple APIs:
Scenario: Complete Purchase Flow
1. User browses products
2. User adds items to cart
3. User applies discount code
4. System calculates total with discount
5. User proceeds to checkout
6. User enters shipping info
7. User makes payment
8. System creates order
9. User receives confirmation
10. Verify order in order history
User Story Validation
Validate acceptance criteria:
User Story:
As a user, I want to update my profile picture
so that other users can recognize me.
Scenario:
1. User logs in
2. User uploads new profile picture
3. System validates image format and size
4. System saves image
5. User views profile
6. New picture is displayed
7. Other users see updated picture
Integration Testing
Test how multiple services work together:
Scenario: Cross-Service Order Processing
1. Create user in User Service
2. Create product in Product Service
3. Add product to cart in Cart Service
4. Create order in Order Service
5. Process payment in Payment Service
6. Update inventory in Product Service
7. Send notification via Notification Service
8. Verify order status across all services
Regression Testing
Ensure features still work after changes:
Scenario: Critical User Journey
Test that existing users can:
1. Login with saved credentials
2. Access their profile
3. View order history
4. Update account settings
5. Logout successfully
Example Scenarios
E-commerce Platform
AI-Detected:
1. Product Discovery
- Browse catalog
- Search products
- Filter by category
- Sort by price
2. Shopping Experience
- Add to cart
- Update quantities
- Apply coupon
- Checkout
3. Order Management
- View orders
- Track shipment
- Cancel order
- Request refund
Manual:
Test that a guest user can browse products,
add items to cart, create account during checkout,
complete payment, and receive order confirmation email.
SaaS Application
AI-Detected:
1. User Onboarding
- Sign up
- Email verification
- Profile setup
- Tutorial completion
2. Subscription Management
- View plans
- Upgrade plan
- Update payment method
- Cancel subscription
Manual:
Test that a free trial user receives upgrade prompts
when reaching usage limits, can upgrade to paid plan,
and immediately gains access to premium features.
Advantages
Business-Focused
- Write tests in business language
- No need to understand API details
- Focus on what matters to users
- Easy for non-technical stakeholders
Comprehensive Coverage
- AI identifies all necessary steps
- Includes setup and cleanup
- Covers error scenarios automatically
- Tests complete workflows
Flexible
- Easy to modify scenarios
- Quick regeneration with changes
- Iterative refinement
- Adapts to API changes
Best Practices
Start Simple
- Begin with single-action scenarios
- Validate results
- Add complexity gradually
- Build multi-step workflows
Use AI Detection First
- Let AI suggest scenarios
- Review and select relevant ones
- Add manual scenarios for specific needs
- Combine both approaches
Be Clear and Concise
- One scenario per test case
- Clear success criteria
- Specific expected behavior
- Avoid ambiguity
Combine with API-Based
- Use API-based for structural coverage
- Use scenario-based for business logic
- Get both technical and functional validation
Troubleshooting
No Scenarios Detected
Solutions:
- Use manual scenario creation
- Improve API documentation
- Add more endpoint descriptions
Wrong APIs Selected
Solutions:
- Be more specific in description
- Explicitly mention API paths
- Review and adjust AI suggestions
Scenario Too Complex
Solutions:
- Split into multiple scenarios
- Focus on one workflow
- Simplify description
Next Steps
- Try API-Based Generation for structural coverage
- Learn about Test Execution
- Explore AI Auto-Fix