close
Skip to content

m4rri4nne/SwaggerIntegration

Repository files navigation

📝 API Contract Test Project

.NET Build Status License

A C# test automation solution for validating APIs against their Swagger/OpenAPI contracts. Ensures that APIs send expected request structures and response payloads, improving reliability, reducing errors, and supporting scalable automation.


🚀 Features

  • Swagger/OpenAPI validation: Ensures APIs match their defined contracts.
  • Request format checks: Verifies all outgoing requests adhere to the expected schema.
  • Response validation: Confirms API responses match expected structures, data types, and status codes.
  • Automated testing: Integrates seamlessly with CI/CD pipelines.
  • Scalable architecture: Easily extendable to cover new APIs and endpoints.

🎯 Advantages of Automated Contract Testing

  1. Early detection of issues – Catch mismatches or missing fields before production.
  2. Improved API quality – Maintain consistent and reliable endpoints.
  3. Reduced manual effort – Automated tests save time and reduce human error.
  4. Safe refactoring – Confidently modify APIs knowing contract tests will catch breaking changes.
  5. CI/CD integration – Continuous validation ensures contracts are always respected.

⚡ Getting Started

Prerequisites

  • .NET 9 SDK
  • Access to API Swagger/OpenAPI specification (JSON)

Installation

git clone https://github.com/m4rri4nne/SwaggerIntegration.git
cd SwaggerIntegration
dotnet restore
dotnet build

Running Tests

dotnet test

⚡ Example Test (C#)

    [Test]
    public async Task CheckSwaggerGetMethod()
    {
        var response = await _requests.GetAsync<string>("api/v1/Activities");
        Assert.That(response.StatusCode, Is.EqualTo(System.Net.HttpStatusCode.OK));
        await _validator.ContractValidation(
            _swaggerUrl,
            "/api/v1/Activities",
            "get",
            200,
            response.Content);
    }

🌱 Future Improvements

  • Dynamic test generation from Swagger definitions.
  • Data-driven testing for multiple scenarios.
  • Support for GraphQL or other API specifications.
  • Reporting dashboards to visualize contract violations.

About

A C# test automation solution for validating APIs against their Swagger/OpenAPI contracts. Ensures that APIs send expected request structures and response payloads, improving reliability, reducing errors, and supporting scalable automation.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages