Skip to content

AI Test Generation

NOIV's AI-powered test generation is one of its most powerful features. Transform natural language descriptions into comprehensive API test suites using advanced AI.

How It Works

NOIV uses Google Gemini AI to understand your natural language descriptions and generate appropriate API tests. Simply describe what you want to test in plain English, and NOIV creates the test scenarios.

Basic Usage

bash
noiv generate natural "test user authentication API"

This simple command generates a complete test suite with multiple scenarios.

Writing Effective Descriptions

The key to getting great test generation results is writing clear, descriptive prompts.

✅ Good Examples

bash
# Comprehensive e-commerce testing
noiv generate natural "test e-commerce API with user registration, product search, shopping cart operations, and checkout process"

# Authentication focus
noiv generate natural "test user management system with login, registration, password reset, and profile updates"

# Error handling
noiv generate natural "test blog API with CRUD operations, authentication, and proper error handling for invalid requests"

❌ Poor Examples

bash
# Too vague
noiv generate natural "test API"

# Too technical/specific
noiv generate natural "POST /api/v1/users with 201 status"

Generated Test Structure

When you run AI generation, NOIV creates a YAML file with this structure:

yaml
name: 'Tests: Your description'
tests:
  - name: Test Case 1
    url: https://api.example.com/endpoint
    method: GET
    expected_status: 200
    headers:
      Content-Type: application/json
    validations:
      - type: json_path
        path: $.data.id
        expected: "exists"
  - name: Test Case 2
    # ... more tests

Advanced Prompting

Specify API Details

Include specific API information for better results:

bash
noiv generate natural "test RESTful user management API at api.myapp.com with JWT authentication, including user CRUD operations and role-based permissions"

Include Error Scenarios

Ask for comprehensive testing including edge cases:

bash
noiv generate natural "test payment processing API with successful payments, declined cards, invalid amounts, and network timeouts"

Multiple Environments

Generate tests for different environments:

bash
noiv generate natural "test social media API for posting, commenting, and user interactions with proper authentication and rate limiting"

Customizing Generated Tests

After generation, you can modify the YAML file to:

Add Custom Headers

yaml
headers:
  Authorization: "Bearer ${API_TOKEN}"
  X-API-Version: "v2"
  Custom-Header: "value"

Include Request Bodies

yaml
body: |
  {
    "username": "testuser",
    "email": "test@example.com",
    "password": "securepass123"
  }

Enhanced Validations

yaml
validations:
  - type: status_code
    expected: 201
  - type: header
    name: Location
    expected: "contains:/users/"
  - type: json_path
    path: $.user.email
    expected: "test@example.com"
  - type: contains
    value: "created successfully"

Real-World Examples

E-commerce Platform

bash
noiv generate natural "test complete e-commerce platform with user authentication, product catalog with search and filtering, shopping cart management, order processing with payment integration, and admin panel for inventory management"

Generated structure:

  • User registration/login tests
  • Product search and filtering
  • Cart operations (add, remove, update)
  • Checkout and payment flow
  • Admin inventory management

Microservices API

bash
noiv generate natural "test microservices architecture with user service, order service, payment service, and notification service, including inter-service communication and circuit breaker patterns"

Content Management System

bash
noiv generate natural "test CMS API with content creation, editing, publishing workflow, media uploads, user permissions, and SEO metadata management"

Best Practices

1. Be Descriptive but Concise

bash
# Good balance
noiv generate natural "test inventory management API with product CRUD, stock tracking, low inventory alerts, and supplier management"

2. Include Business Logic

bash
# Includes business rules
noiv generate natural "test booking system with availability checking, reservation creation, cancellation policies, and payment processing with refund handling"

3. Mention Authentication

bash
# Security-aware
noiv generate natural "test secure API with OAuth2 authentication, role-based access control, and data validation for financial transactions"

4. Specify Data Types

bash
# Data-specific
noiv generate natural "test analytics API with time-series data collection, aggregation queries, dashboard metrics, and CSV export functionality"

Environment Variables

Use environment variables in your tests for different environments:

yaml
tests:
  - name: Login Test
    url: "${BASE_URL}/auth/login"
    headers:
      Authorization: "Bearer ${API_TOKEN}"

Set them before running:

bash
export BASE_URL="https://staging-api.example.com"
export API_TOKEN="your-token-here"
noiv test run generated_tests.yaml

Troubleshooting

AI Generation Issues

If generation doesn't work as expected:

  1. Check internet connection - AI features require connectivity
  2. Simplify your prompt - Try a shorter, clearer description
  3. Be more specific - Add details about the API you're testing
  4. Review output - Generated tests may need manual adjustments

Common Fixes

bash
# If generation fails, try simpler prompts
noiv generate natural "test user login and registration"

# Then build up complexity
noiv generate natural "test user authentication system with email verification and password reset"

Next Steps

TIP

Generated tests are starting points. Feel free to modify the YAML files to match your specific API requirements and add custom validations.

Released under the MIT License.