A powerful C# CLI application for comprehensive API testing, enabling developers to streamline API validation workflows with rich configuration and execution capabilities.
- Multiple Request Methods: Support for GET, POST, PUT, DELETE, and more
- Rich Payload Types: JSON, Text, Form Data
- File Upload Support: Test multipart/form-data requests with file uploads
- Environment Variables: Use different configurations for development, staging, production
- Test Assertions: Validate response status, headers, body content
- Detailed Reports: Comprehensive output with request and response details
- Single File Deployment: Simplified deployment as a single executable file
- .NET 9 Ready: Automatic multi-targeting with .NET 9.0 when available
- .NET 8.0 SDK (required)
- .NET 9.0 SDK (optional, for building with .NET 9.0 when available)
# Clone the repository
git clone https://github.com/yourusername/api-tester.git
cd api-tester
# Build the project
dotnet build
# Run the application
dotnet run
For simplified deployment, you can build a single executable file:
# Build a single file executable
dotnet publish -c Release -r linux-x64 --self-contained true
# Windows:
# dotnet publish -c Release -r win-x64 --self-contained true
# macOS:
# dotnet publish -c Release -r osx-x64 --self-contained true
# macOS ARM64:
# dotnet publish -c Release -r osx-arm64 --self-contained true
You can use API Tester within your existing API projects:
-
Build and Install API Tester
# Build as a single file executable dotnet publish -c Release -r <your-platform> --self-contained true # Copy the executable to a location in your PATH, or use it directly cp bin/Release/net8.0/<your-platform>/publish/apitester /usr/local/bin/ # or for Windows # copy bin\Release\net8.0\win-x64\publish\apitester.exe C:\path\to\your\bin\
-
Initialize API Testing in Your Project Directory
# Navigate to your API project cd /path/to/your/weatherapi # Initialize API testing (creates apify-config.json and apis/ directory) apitester init --name "Weather API Tests" --base-url "https://api.weather.com" # If you didn't install globally, use the full path to the executable # /path/to/apitester init --name "Weather API Tests" --base-url "https://api.weather.com"
-
Create API Test Definitions
- Add test files to the
apis/
directory in your project - Each JSON file represents an API endpoint test
- Add test files to the
-
Run Tests
# From your project directory where apify-config.json is located apitester run apis/get-weather.json # Run with verbose output apitester run apis/get-weather.json --verbose # Run with a specific environment apitester run apis/get-weather.json --env Production
-
View Environment Configuration
# From your project directory apitester list-env
dotnet run init --name "My API Project" --base-url "https://api.example.com"
# Run a specific test
dotnet run run apis/sample-api.json
# Run with verbose output
dotnet run run apis/sample-api.json --verbose
# Run with a specific environment
dotnet run run apis/sample-api.json --env Production
dotnet run list-env
This project includes GitHub Actions workflows for continuous integration and releases.
The CI workflow runs on every push to the main branch and pull requests. It:
- Builds the project on Windows, Linux, and macOS
- Runs API tests to verify functionality
- Ensures compatibility across all supported platforms
To create a release:
-
Tag-based release:
- Create and push a new tag:
git tag -a v1.0.0 -m "Version 1.0.0" && git push origin v1.0.0
- Create and push a new tag:
-
Manual release:
- Go to the Actions tab in your GitHub repository
- Select the "Release" workflow
- Click "Run workflow"
- Enter the version number (e.g., "1.0.0")
This will:
- Build single file executables for Windows, Linux, macOS (x64), and macOS (ARM64)
- Create a GitHub release with the executables attached
- Tag the release with the specified version
API tests are defined in JSON files with this structure:
{
"Name": "Sample API Test",
"Description": "Tests the sample endpoint",
"Uri": "https://api.example.com/endpoint",
"Method": "GET",
"Headers": {
"Accept": "application/json",
"Authorization": "Bearer {{token}}"
},
"Payload": {
"name": "John Doe",
"email": "john@example.com"
},
"PayloadType": "json",
"Tests": [
{
"Name": "Status code is successful",
"AssertType": "StatusCode",
"ExpectedValue": "200"
}
]
}
Here's a practical example of how to use API Tester with a Weather API project:
# Navigate to your Weather API project
cd ~/projects/weatherapi
# Initialize API testing (creates apify-config.json and apis/ directory)
apitester init --name "Weather API Tests" --base-url "https://api.weather.com"
Create a file apis/get-current-weather.json
:
{
"Name": "Get Current Weather",
"Description": "Tests the current weather endpoint",
"Uri": "{{baseUrl}}/current?location={{location}}",
"Method": "GET",
"Headers": {
"Accept": "application/json",
"X-API-Key": "{{apiKey}}"
},
"Tests": [
{
"Name": "Status code is 200",
"AssertType": "StatusCode",
"ExpectedValue": "200"
},
{
"Name": "Response contains temperature",
"Assertion": "response.body.$.current.temperature exists"
},
{
"Name": "Response contains location details",
"Assertion": "response.body.$.location.name == {{location}}"
}
]
}
Edit apify-config.json
to add your environment variables:
{
"Name": "Default",
"Description": "Weather API Configuration",
"DefaultEnvironment": "Development",
"Environments": [
{
"Name": "Development",
"Description": "Development environment",
"Variables": {
"baseUrl": "https://api.weather.com/v1",
"location": "New York",
"apiKey": "your-dev-api-key"
}
},
{
"Name": "Production",
"Description": "Production environment",
"Variables": {
"baseUrl": "https://api.weather.com/v1",
"location": "New York",
"apiKey": "your-prod-api-key"
}
}
]
}
# From your Weather API project directory
apitester run apis/get-current-weather.json --verbose