Testing Overview
Testing ensures your API works correctly and continues to work as you make changes. This guide covers various testing approaches for the Medical Appointment Management API.Testing with Scalar UI
The easiest way to test the API is through the built-in Scalar documentation interface.Access Scalar
Start the API and navigate to:Testing Workflow
Advantages of Scalar
- No additional tools needed
- Automatic documentation sync
- Request/response schema validation
- Code generation for multiple languages
- Beautiful, modern interface
Testing with cURL
For command-line testing or automation, use cURL.GET Requests
List all patients:POST Requests
Create a new specialty:PUT Requests
Update a patient:DELETE Requests
Delete a patient:Pretty-Print JSON Responses
Pipe cURL output throughjq for formatted JSON:
Testing with HTTPie
HTTPie provides a more user-friendly alternative to cURL.Installation
Usage Examples
GET request:Testing with Postman
Postman is a popular GUI tool for API testing.Setup
- Download Postman from postman.com
- Create a new collection called “Medical Appointment API”
- Add the base URL as a collection variable:
{{baseUrl}} = https://localhost:5001
Creating Requests
- Click New Request
- Set method (GET, POST, PUT, DELETE)
- Enter URL:
{{baseUrl}}/api/Paciente - For POST/PUT, go to Body → raw → JSON and enter your data
- Click Send
Environment Variables
Create environments for different stages: Development:baseUrl=https://localhost:5001
baseUrl=https://api.yourapp.com
Collection Runner
Run multiple requests in sequence:- Click Runner in Postman
- Select your collection
- Click Run
Unit Testing Services
Test services independently without HTTP infrastructure.Setup xUnit
Example: Testing PacienteService
Tests/PacienteServiceTests.cs
Run Unit Tests
Integration Testing Controllers
Test the full HTTP request/response cycle.Setup
Example: Testing PacienteController
Tests/PacienteControllerTests.cs
Test Data Management
Creating Test Data
Create helper methods for generating test data:Tests/TestDataFactory.cs
End-to-End Testing Scenarios
Scenario: Complete Appointment Booking
Complete appointment workflow
Performance Testing
Using Apache Bench
Test API performance:Using wrk
Test Coverage
Generate Code Coverage Report
Best Practices
Test Business Logic
Focus unit tests on service layer where business logic lives
Use Integration Tests
Test full HTTP flow for critical user journeys
Arrange-Act-Assert
Structure tests clearly: setup, execute, verify
Meaningful Test Names
Use descriptive names:
Method_Scenario_ExpectedResultTest Edge Cases
Test null values, empty lists, invalid input
Isolate Tests
Each test should be independent and repeatable
Common Test Scenarios
Validation Testing
Conflict Detection Testing
Continuous Integration
Add testing to your CI/CD pipeline:.github/workflows/test.yml
Next Steps
Development Guide
Learn how to extend the API
Architecture
Understand the system design
API Reference
Explore all endpoints
Services
Deep dive into service patterns