Skip to main content

Your First Test

This guide will walk you through running your first API test with Dochia. You'll learn how to execute negative and boundary tests against your API using Dochia's 100+ playbooks.

Prerequisitesโ€‹

Before running your first test, ensure you have:

  1. Dochia installed - See Installation Guide
  2. An OpenAPI specification - Your API contract in YAML or JSON format
  3. A running API server - The service you want to test

Basic Test Commandโ€‹

The simplest way to run a test is with the basic command structure:

dochia test --contract <your-api-spec.yaml> --server <your-api-url>

Example: Testing a Local APIโ€‹

# Test a local API running on port 8080
dochia test --contract openapi.yaml --server http://localhost:8080

Example: Testing a Remote APIโ€‹

# Test a remote API
dochia test --contract api-spec.json --server https://api.example.com

Understanding the Outputโ€‹

When you run a test, Dochia will:

  1. Parse your OpenAPI spec - Analyze endpoints, parameters, and schemas
  2. Generate test cases - Create negative and boundary tests using 100+ playbooks
  3. Execute tests - Send requests to your API server
  4. Generate reports - Create detailed HTML reports in the dochia-report/ folder

Sample Outputโ€‹

Starting dochia-cli-1.0.1, build time 2025-08-12T14:34:53Z UTC

๐Ÿงช Running tests...
/public/events ................................................... E 99, W 4, S 82 โœ”

โ˜‘ 185 tests completed in 2.354s
โœ” 82 passed, โš  4 warnings, โจฏ 99 errors

โ˜‘ Full Report: file:///Users/dochia-fan/openapi-project/dochia-report/index.html

Dry Run - Preview Without Executionโ€‹

Before running actual tests, use --dry-run to see what Dochia will test:

# Preview test execution without making requests
dochia test --contract openapi.yaml --server http://localhost:8080 --dry-run

This will show how many tests will be executed per path.

Common Test Scenariosโ€‹

1. Testing with Authenticationโ€‹

If your API requires authentication, use headers:

# Using API key authentication
dochia test --contract openapi.yaml --server http://localhost:8080 \
--header "Authorization=Bearer your-jwt-token"

# Using environment variables
dochia test --contract openapi.yaml --server http://localhost:8080 \
--header "API-Key=$API_TOKEN"

2. Testing Specific Endpointsโ€‹

Test only specific paths instead of all endpoints:

# Test only user-related endpoints
dochia test --contract openapi.yaml --server http://localhost:8080 \
--paths "/users,/users/{id}"

3. Testing Specific HTTP Methodsโ€‹

Focus on particular HTTP methods:

# Test only POST and PUT operations
dochia test --contract openapi.yaml --server http://localhost:8080 \
--http-methods "POST,PUT"

4. Blackbox Testingโ€‹

Run in blackbox mode to only report server errors (5XX codes):

# Only report 500-level errors
dochia test --contract openapi.yaml --server http://localhost:8080 --blackbox

Playbook Categoriesโ€‹

Dochia organizes tests into different categories:

Body Playbooksโ€‹

Test request body validation and handling:

# Run only body-related tests
dochia test --contract openapi.yaml --server http://localhost:8080 --body-only

Header Playbooksโ€‹

Test HTTP header handling:

# Run only header-related tests
dochia test --contract openapi.yaml --server http://localhost:8080 --headers-only

Field Playbooksโ€‹

Test individual field validation:

# Run only field-related tests
dochia test --contract openapi.yaml --server http://localhost:8080 --fields-only

Configuration Filesโ€‹

For complex scenarios, use configuration files:

Custom Headers Fileโ€‹

Create a headers.yaml file:

/users:
Authorization: Bearer token123
Content-Type: application/json
/orders:
API-Key: your-api-key

Use it in your test:

dochia test --contract openapi.yaml --server http://localhost:8080 \
--headers headers.yaml

Reference Data Fileโ€‹

Create a reference-data.yaml for required field values:

/users:
tenantId: "test-tenant"
organizationId: "org-123"

Use it in your test:

dochia test --contract openapi.yaml --server http://localhost:8080 \
--reference-data reference-data.yaml

Rate Limiting and Timeoutsโ€‹

Configure request timing to respect API limits:

# Limit to 100 requests per minute with custom timeouts
dochia test --contract openapi.yaml --server http://localhost:8080 \
--max-requests-per-minute 100 \
--connection-timeout 30 \
--read-timeout 30

Viewing Resultsโ€‹

After test execution, Dochia generates comprehensive reports:

HTML Reportโ€‹

Open dochia-report/index.html in your browser to see:

  • Test execution summary
  • Detailed results for each test case
  • Failed requests with full request/response details
  • Playbook coverage information

Console Outputโ€‹

Use verbosity flags for more detailed console output:

# Increase verbosity for detailed logging
dochia test --contract openapi.yaml --server http://localhost:8080 -vvv

Exit Codesโ€‹

Dochia uses specific exit codes to indicate results:

  • 0 - All tests passed successfully
  • 191 - Usage error (incorrect command syntax)
  • 192 - Internal execution error
  • N - Number of errors found (e.g., exit code 5 means 5 errors)

Troubleshooting Common Issuesโ€‹

Connection Refusedโ€‹

Error: Connection refused to http://localhost:8080

Solution: Ensure your API server is running and accessible.

Invalid OpenAPI Specโ€‹

Error: Unable to parse OpenAPI specification

Solution: Validate your OpenAPI spec using online validators.

Authentication Failuresโ€‹

Warning: Many 401/403 responses detected

Solution: Check your authentication headers and credentials.

Rate Limitingโ€‹

Warning: Many 429 responses detected

Solution: Reduce request rate with --max-requests-per-minute.

Next Stepsโ€‹

Now that you've run your first test:

  1. Explore CLI Commands - Learn about all available commands
  2. Understand Basic Concepts - Deep dive into how Dochia works
  3. View Examples - See real-world testing scenarios
  4. Advanced Configuration - Customize Dochia for complex APIs

Quick Referenceโ€‹

# Basic test
dochia test -c api.yaml -s http://localhost:8080

# Dry run
dochia test -c api.yaml -s http://localhost:8080 --dry-run

# With authentication
dochia test -c api.yaml -s http://localhost:8080 -H "Authorization=Bearer token"

# Blackbox mode
dochia test -c api.yaml -s http://localhost:8080 --blackbox

# Specific paths
dochia test -c api.yaml -s http://localhost:8080 --paths "/users,/orders"

# Custom output location
dochia test -c api.yaml -s http://localhost:8080 --output my-reports/