API Testing Guide
This guide explains how to run the API tests for the RealWorld application.
Overview
The API tests are implemented using Postman collections and can be run locally against your backend. These tests ensure that your API implementation meets the RealWorld API specification.
Prerequisites
- pnpm installed
- newman (will be installed automatically via pnpm)
- Your backend server running locally
Running the Tests
Basic Usage
To run the tests against your local backend, execute:
APIURL=http://localhost:8001/api ./tools/test/run-api-tests.sh
Configuration Options
The test script supports several environment variables for customization:
Variable | Description | Default Value |
---|---|---|
APIURL | The base URL of your API | http://localhost:8001/api |
USERNAME | Username for test user | u[timestamp] |
Email for test user | [username]@mail.com | |
PASSWORD | Password for test user | password |
Examples
- Run with custom user credentials:
APIURL=http://localhost:8001/api \
USERNAME=testuser \
EMAIL=test@example.com \
PASSWORD=testpass \
./tools/test/run-api-tests.sh
- Run against a different environment:
APIURL=https://api.example.com/api ./tools/test/run-api-tests.sh
Test Collection
The tests are defined in the Postman collection file: tools/test/realworld.postman_collection.json
. This collection includes tests for all endpoints specified in the RealWorld API specification.
Troubleshooting
If you encounter issues:
- Ensure your backend server is running and accessible
- Check that the APIURL is correct and points to your API
- Verify that your API implements all endpoints required by the RealWorld specification
- Check the test output for specific error messages
Additional Resources
Last updated on