Best Practices for Using Dochia
This guide provides best practices for using Dochia effectively, from preparing your OpenAPI specification to integrating with CI/CD and managing test data.
OpenAPI Specification Quality
A high-quality OpenAPI spec is the foundation of effective testing with Dochia.
-
Be Specific with Data Types and Formats:
- Define
formatfor strings (e.g.,date-time,email,uuid). - Use
enumfor fields with a limited set of values. - Specify
minLength,maxLength,minimum, andmaximumconstraints.
- Define
-
Provide Examples:
- Include
examplevalues for complex objects and required fields. - Use realistic examples to guide Dochia's test generation.
- Include
-
Define Security Schemes:
- Clearly define
securitySchemes(e.g., OAuth 2.0, API Key, Basic Auth). - Apply security requirements to endpoints using the
securitykeyword.
- Clearly define
-
Use Tags for Organization:
- Group related endpoints with
tags(e.g.,users,products,orders). - Use tags to run tests on specific parts of your API.
- Group related endpoints with
Test Configuration
Optimize your test runs with these configuration best practices.
-
Start with a Dry Run:
- Use
--dry-runto preview tests without making requests. - Verify that Dochia is targeting the correct endpoints and generating valid payloads.
- Use
-
Scope Your Tests:
- Use
--paths,--http-methods, and--tagsto focus on specific areas. - Run targeted tests for faster feedback and easier debugging.
- Use
-
Use External Configuration Files:
- Manage headers, query parameters, and reference data in YAML files.
- Keep your test commands clean and your configurations reusable.
-
Leverage Reference Data:
- Use
--reference-datato provide required field values. - Use per-path overrides for context-specific data.
- Use SpringEL for dynamic values (e.g., timestamps, UUIDs).
- Use
-
Manage Authentication Securely:
- Use environment variables for secrets (
$$API_KEY). - Use
--auth-refresh-scriptfor dynamic token generation. - Use
--mask-headersto hide sensitive data in reports.
- Use environment variables for secrets (
CI/CD Integration
Integrate Dochia into your CI/CD pipeline for automated testing.
-
Fail on Errors:
- Dochia exits with the number of errors, which will fail your CI job.
- Use
--blackbox(blackbox mode) to fail only on 5xx errors in non-production environments.
-
Automate Installation:
- Use a script to download and install the correct Dochia version.
- Cache the binary to speed up subsequent runs.
-
Run Targeted Tests:
- Run a quick smoke test on every commit.
- Run a full regression suite on a nightly or scheduled basis.
-
Publish Reports:
- Use
--outputto save reports to a specific directory. - Archive reports as build artifacts for later analysis.
- Use
Performance and Tuning
Optimize Dochia's performance for your environment.
-
Adjust Rate Limiting:
- Use
--max-requests-per-minuteto avoid overwhelming your API. - Start with a conservative value and increase as needed.
- Use
-
Configure Timeouts:
- Use
--connection-timeout,--read-timeout, and--write-timeoutto handle slow responses. - Increase timeouts for long-running operations.
- Use
-
Use Blackbox Mode:
- Use
--blackboxto ignore non-5xx errors when testing unstable environments. - Focus on critical server errors rather than expected validation failures.
- Use
-
Monitor Performance:
- Use
--execution-statsto get performance metrics. - Identify slow endpoints and performance bottlenecks.
- Use
Test Data Management
Manage your test data effectively for reliable and repeatable tests.
-
Use a Test Data Seeding Script:
- Run a script to populate your database with known test data before running Dochia.
- Ensure your tests run against a consistent and predictable state.
-
Clean Up After Tests:
- Run a script to clean up created resources after tests complete.
- Avoid polluting your test environment with leftover data.
-
Use Dynamic Data for Unique Resources:
- Use SpringEL expressions (
${...}) to generate unique identifiers. - Avoid collisions and ensure tests are independent.
- Use SpringEL expressions (
-
Version Control Your Configurations:
- Commit your reference data, headers, and query parameter files.
- Keep your test configurations in sync with your codebase.
See Also
- CI/CD Integration - Detailed guide on integrating Dochia with CI/CD.
- Using Reference Data - In-depth guide on reference data.
- Authentication Flows - Securely managing authentication.
- Troubleshooting - Common issues and solutions.