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

Getting Started: Your First Test Scenario

This is where you create your first automated test. In the next 20 minutes, you'll go from zero to having a working test scenario that automatically verifies your Pet Store User API works correctly. No complex setup. No confusing concepts. Just results.

Before you start#

Make sure you've completed the Developing APIs chapter and have your Pet Store User API running locally. If you haven't already, start it with:
Your API should be running at http://localhost:8000. You should see the FastAPI docs at http://localhost:8000/docs showing your six endpoints:
POST /users - User registration
POST /user/login - Login with JWT token
GET /users/{id} - Get user profile
PUT /users/{id} - Update user
DELETE /users/{id} - Delete account
POST /user/logout - Logout
Here's what we're doing:
1.
Create a test scenario in Apidog (2 minutes)
2.
Add a test step for user registration (5 minutes)
3.
Run the test and see the results (3 minutes)
Let's go.

Create Your First Test Scenario#

A test scenario in Apidog is like a collection of related tests. Think of it as a folder where you organize tests that belong together. For example, you might have a "User Registration Tests" scenario, or a "Complete User Lifecycle" scenario.

Open the Tests module#

In Apidog, click on Tests in the left sidebar. You'll see the test scenarios list (probably empty if this is your first time).

Create a new test scenario#

1.
Click the + button next to the search bar at the top
2.
A dialog appears asking for:
Name: Enter "User Registration Test"
Directory: Choose where to save it (or create a new folder)
Priority: Leave as default for now
3.
Click Create
You now have an empty test scenario. It's like an empty folder waiting for tests.

Why test scenarios matter#

Test scenarios help you organize tests logically. Instead of having dozens of individual tests scattered around, you group related tests together. This makes it easier to:
Find tests when you need them
Run related tests together
Share test suites with your team
Maintain tests as your API grows

Add Your First Test Step#

Now let's add an actual test. We'll test the user registration endpoint (POST /users).

Add a test step#

In your test scenario, click Add Step (or the + button). You'll see several options for adding requests:

Option 1: Import from endpoint spec (Recommended for beginners)#

This imports the endpoint directly from your API specification. It's the easiest way to get started:
1.
Click Import from endpoint spec
2.
You'll see a list of all endpoints in your project
3.
Find and select POST /users (the user registration endpoint)
4.
Choose Manual sync mode (we'll explain this later)
5.
Click Add
The endpoint is now added as a test step. You can see it in your scenario with all the request details already filled in from your API spec.

Option 2: Import from endpoint case#

If you've already created endpoint cases (saved requests with specific parameters), you can import those instead. This is useful when you have pre-configured test data.

Option 3: Add custom request#

For testing endpoints outside your project or creating custom requests, use this option. You can create any HTTP request from scratch.

Understanding the difference#

Import from spec: Always matches your API design. If you update the endpoint in your API spec, you can sync the test step to match.
Import from case: Uses pre-configured parameters. Good for standardized tests with specific data.
Custom request: Maximum flexibility. Use for testing third-party APIs or edge cases.
For now, stick with "Import from endpoint spec." It's the simplest and keeps your tests aligned with your API design.

Configure Your Test Request#

When you import an endpoint from the API spec, Apidog automatically fills in the request structure based on your API design. The request body, parameters, and headers are already configured according to your endpoint specification.
If you've created endpoint cases in the Designing APIs chapter, those test data will be automatically used. Otherwise, Apidog will use the default values from your API schema. You can modify the test data if needed, but for now, the auto-generated test case should work perfectly for testing your Pet Store User API.

Choose your environment#

At the top right, make sure you've selected the correct environment. If your Pet Store User API is running locally, select Local Development (or whatever you named your local environment). The base URL should be http://localhost:8000 (where your FastAPI server is running).
If you haven't created a local environment yet:
1.
Click Environments in the sidebar
2.
Click + New Environment
3.
Name it "Local Development"
4.
Set Base URL to http://localhost:8000
5.
Save and switch to this environment

Why this matters#

The environment determines where your test requests are sent. You can have different environments for:
Local development (http://localhost:8000)
Staging (https://api-staging.example.com)
Production (https://api.example.com)
Switch between them easily without changing your test scenarios.

Run Your First Test#

Now comes the exciting partโ€”running your test and seeing if it works.

Run the test scenario#

1.
Make sure your Pet Store User API is running locally at http://localhost:8000
2.
Select the environment in which you want the requests to run (Local Development)
3.
Click the Run button at the top of the test scenario
4.
Apidog will send the request to your local API and show you the results
Select environment and run

What you'll see#

After running, you'll see a test report showing:
Status: Passed or Failed
Response: The actual response from your API
Response time: How long the request took
Status code: The HTTP status code (should be 201 for successful registration)
Test report
If everything worked, you'll see a green checkmark and status code 201. The response should include the created user object with fields like id, email, firstName, lastName, and createdAt, but not the password (which is correctly excluded for security). Congratulationsโ€”you just ran your first automated test for your Pet Store User API!

Understanding the test report#

The test report shows you exactly what happened:
Request details: What was sent to the API
Response details: What the API returned
Timing information: How long everything took
Click on "more" to inspect the actual request and response details:
Test report details
This is valuable information. You can see if the API responded correctly, how fast it was, and what data it returned. All automatically, without manually checking anything.
See details Running Tests

Key Takeaways#

Use Test Scenarios for organizing and running tests
Import efficiently from API specs or cases
Verify results using practical examples (e.g. user registration)

What's Next#

You have a working test scenario, but it's pretty basic. Right now, it just sends a request and shows you the response. It doesn't verify that the response is correct, or check that the data was stored properly.
In the next chapter, we'll learn how to:
Pass data between multiple requests (like using a token from login in subsequent requests)
Add assertions to verify responses are correct
Build complete integration tests that test entire workflows
You'll see how to test the complete Pet Store User API lifecycle: register โ†’ login โ†’ update โ†’ delete. All automatically, all verified. We'll use the same Pet Store User API you built in the Developing APIs chapter, so you'll be testing a real, working API.
Continue with โ†’ Integration Testing and Data Passing
Modified atย 2025-12-25 09:52:39
Previous
Testing APIs: Overview
Next
Integration Testing and Data Passing
Built with