API Academy
🌐 English
  • 🌐 English
  • 🌐 繁體中文
HomePetstore APIExplore more APIs
HomePetstore APIExplore more APIs
🌐 English
  • 🌐 English
  • 🌐 繁體中文
🌐 English
  • 🌐 English
  • 🌐 繁體中文
  1. Testing APIs
  • Introduction
  • Table of Contents
  • API Academy
    • Get Started
      • What is an API?
      • How Does an API Work?
      • How to Call an API?
      • How to Read an API Documentation?
      • Chapter Summary
      • Get realtime weather
    • API Fundamentals
      • API Funtamentals: Overview
      • Method & Path
      • Parameters
      • Request Body
      • Responses
      • API Specification & OAS
      • Chapter Summary
    • Working with APIs
      • Working with APIs: Overview
      • Making Requests from Spec
      • Environments and Variables
      • Chaining Multiple Endpoints
      • Handling Authentication
      • Handling API Signatures
      • Introduction to Scripts
      • Chapter Summary
    • Mocking APIs
      • Mocking APIs: Overview
      • Smart Mock
      • Mock Expectations
      • Cloud Mock
      • Mock Scripts
      • Chapter Summary
    • Designing APIs
      • Designing APIs: Overview
      • Introduction to API Design
      • Creating Your First API Project
      • Analyzing Requirements and Planning Your API
      • Designing Data Models
      • Designing Endpoints
      • Using Components and Reusability
      • Setting Up Authentication
      • API Design Guidelines
      • Chapter Summary
    • Developing APIs
      • Developing APIs: Overview
      • Setup: Install Your AI Coding Assistant
      • Quick Start: From Spec to Running API in 30 Minutes
      • Understanding the Generated Code
      • Testing Your API with Apidog
      • Deployment: Put Your API Online
      • Chapter Summary
    • Testing APIs
      • Testing APIs: Overview
      • Getting Started: Your First Test Scenario
      • Integration Testing and Data Passing
      • Dynamic Values
      • Assertions and Validations
      • Flow Control: If, For, ForEach
      • Data-Driven Testing
      • Performance Testing
      • Test Reports and Analysis
      • CI/CD Integration
      • Scheduled Tasks and Automation
      • Advanced Testing Strategies
      • Chapter Summary
    • API Documentations
      • API Documentations: Overview
      • Publishing Your First API Doc
      • Customizing Documentation Appearance
      • Interactive Features for Consumers
      • Advanced Publishing Settings
      • Managing API Versions
      • Chapter Summary
    • Advanced API Technologies
      • API Technologies: Overview
      • GraphQL
      • gRPC
      • WebSocket
      • Socket.IO
      • Server-Sent Events (SSE)
      • SOAP
      • Chapter Summary
    • API Lifecycle
      • API Lifecycle: Overview
      • Stages of the API Lifecycle
      • API Governance
      • API Security Best Practices
      • Monitoring and Analytics
      • API Versioning Strategies
      • The Future of APIs
      • Chapter Summary
    • API Security
      • API Security: Overview
      • API Security Fundamentals
      • Authentication vs Authorization
      • Understanding OAuth 2.0 and OpenID Connect
      • JSON Web Tokens (JWT)
      • OWASP API Security Top 10
      • Encryption and HTTPS
      • Chapter Summary
    • API Tools
      • API Tools: Overview
      • The Evolution of API Tools
      • API Clients
      • Command Line Tools (cURL, HTTPie)
      • API Design and Documentation Tools
      • API Mocking Tools
      • API Testing Tools
      • All-in-One API Platforms
      • Chapter Summary
    • API Gateway
      • API Gateway: Overview
      • What is an API Gateway?
      • Key Features of API Gateways
      • API Gateway vs Load Balancer vs Service Mesh
      • Popular API Gateway Solutions
      • The BFF (Backend for Frontend) Pattern
      • Chapter Summary
  • Modern Pet Store
    • Pet
      • Get Pet
      • Update Pet
      • Delete Pet
      • Create Pet
      • List Pets
      • Upload Pet Image
    • User
      • Update User
      • Get User
      • Delete User
      • Login
      • Logout
      • Create User
    • Store
      • List Inventory
      • Create Order
      • Get Order
      • Delete Order
      • Callback Example
      • Pay for an Order
    • Payments
      • Pay Order
    • Chat
      • Create Chat Completion
    • Webhooks
      • Pet Adopted Event
      • New Pet Available Event
  • Schemas
    • Pet
    • Category
    • User
    • ApiResponse
    • OrderPayment
    • Tag
    • Order
    • Links-Order
    • PetCollection
    • Bank Card
    • Bank Account
    • Links
    • Error
HomePetstore APIExplore more APIs
HomePetstore APIExplore more APIs
🌐 English
  • 🌐 English
  • 🌐 繁體中文
🌐 English
  • 🌐 English
  • 🌐 繁體中文
  1. Testing APIs

Data-Driven Testing

Testing with a single set of data (like "user1") is a good start, but it doesn't prove your API is robust. What happens if the username has spaces? What if it's 100 characters long? What if the email is invalid?
Data-Driven Testing (DDT) allows you to run the same test scenario multiple times, using a different set of data from an external file (CSV or JSON) for each iteration.

What is Data-Driven Testing?#

Instead of hardcoding values like "username": "testuser", you use variables like "username": "{{username}}". You then feed a table of data into the test runner.
Why use it?
1.
Coverage: Test 100 edge cases in seconds.
2.
Efficiency: Write the test logic once, run it endlessly.
3.
Separation: Keep your test logic separate from your test data.

Step 1: Prepare Your Data#

Apidog supports CSV and JSON formats. CSV is usually easiest to manage in Excel or Google Sheets.

Example CSV (users.csv)#

Create a file with headers matching your variable names:
username,email,password,expected_status
valid_user,valid@email.com,Pass123!,201
short_pass,valid2@email.com,123,400
bad_email,notanapemail,Pass123!,400
long_user,user_with_very_long_name_check_limits@email.com,Pass123!,201
Note: The headers (username, email) will automatically become variable names in Apidog.

Step 2: Configure the Test Scenario#

1.
Open your Test Scenario (e.g., "User Registration").
2.
In your API Request (POST /users), replace the hardcoded values with variables:
Body:
{
  "username": "{{username}}",
  "email": "{{email}}",
  "password": "{{password}}"
}
3.
Update Assertions: Since the expected result changes (some pass, some fail), make your assertion dynamic too!
Assertion: Response.status.code Equals {{expected_status}}

Step 3: Import Data and Run#

Now, let's connect the data file to the test runner.
1.
Click the Run button for your scenario.
2.
In the run settings, look for the Test Data section.
3.
Click Import and select your users.csv file.
4.
Preview: Apidog will show you the preview of loaded data rows.
5.
Run: Click Run.
Importing Test Data
See details: Data-Driven Testing

Step 4: Analyze Results#

Apidog will execute the scenario once for every row in your CSV file. In our example, Iteration 1 uses valid_user and expects a 201, which should pass. Iteration 2 uses short_pass, which is invalid. Since we configured the expected status to be 400, the test passes because the API correctly rejected the bad data.
The report groups these by iteration, allowing you to see exactly which data row caused a failure.

Best Practices#

1.
Include Expected Results: As seen in the example (expected_status), put your success criteria IN the data file. This allows one test script to handle both positive and negative tests.
2.
Keep Data Small: Don't upload a 1GB CSV. Stick to key representative cases.
3.
Random vs. Sequential: Apidog usually processes rows sequentially (Row 1, then Row 2). This is deterministic and recommended.

Key Takeaways#

Externalize test data for scalability
Use CSV/JSON files for data driving
Apply data-driven approaches for batch testing

What's Next#

We've covered functional testing, integration logic, and data coverage. But does your API scale? Can it handle 1,000 users at once?
In the next chapter, we'll dive into Performance Testing using Apidog.
Continue with β†’ Performance Testing
Modified atΒ 2025-12-25 09:53:40
Previous
Flow Control: If, For, ForEach
Next
Performance Testing
Built with