Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] Increase unit and integration test coverage #114

Open
guibranco opened this issue Dec 6, 2023 · 1 comment
Open

[FEATURE] Increase unit and integration test coverage #114

guibranco opened this issue Dec 6, 2023 · 1 comment
Labels
CI/CD dependencies Pull requests that update a dependency file documentation Improvements or additions to documentation enhancement gitauto .NET Pull requests that update .net code resilience security tests

Comments

@guibranco
Copy link
Owner

guibranco commented Dec 6, 2023

Description

The current C# HTTP client library needs improved test coverage to ensure robustness and catch edge cases. This includes both unit tests and integration tests that cover a wider range of scenarios.

Objective

  • Expand unit test coverage to include more edge cases, failure scenarios, and specific API behaviors.
  • Add integration tests to validate end-to-end functionality with external dependencies mocked.

Tasks

  1. Unit Tests:

    • Use XUnit for writing the test cases.
    • Use NSubstitute for mocking internal dependencies.
    • Use FluentAssertions for asserting results and better readability.
    • Utilize Snapshooter for snapshot testing and result comparisons to ensure consistent responses over time.
  2. Integration Tests:

    • Use WireMock to mock HTTP requests and simulate different responses from external services (success, failures, timeouts).
    • Write integration tests that simulate real-world scenarios with the library making requests to mocked endpoints.

Requirements:

  • Unit Test Coverage:

    • Cover methods in the library that currently lack sufficient testing.
    • Add tests for various input/output combinations, edge cases, and error handling scenarios.
  • Integration Test Scenarios:

    • Simulate successful HTTP responses, error conditions (404, 500), and network failures.
    • Verify the proper handling of timeout and retry policies (if applicable).
    • Ensure the client handles different HTTP methods (GET, POST, PUT, DELETE) correctly.

Test Strategy:

  • XUnit for test framework.
  • NSubstitute for mocking dependencies and external services.
  • FluentAssertions for clearer and more expressive assertions.
  • Snapshooter for comparison of API responses and ensuring consistent behavior.
  • WireMock for simulating different API responses, ensuring the HTTP client reacts correctly in various scenarios.

Example:

public class HttpClientTests
{
    private readonly IExternalService _mockService = Substitute.For<IExternalService>();
    
    [Fact]
    public async Task Should_Return_Correct_Response_On_Success()
    {
        // Arrange
        var expectedResponse = new ApiResponse { ... };
        var client = new HttpClient(_mockService);
        
        _mockService
            .GetAsync(Arg.Any<string>())
            .Returns(Task.FromResult(expectedResponse));
        
        // Act
        var result = await client.GetDataAsync();
        
        // Assert
        result.Should().BeEquivalentTo(expectedResponse);
        Snapshot.Match(result);  // Snapshooter for result comparison
    }
}

Additional Notes:

  • The tests should be structured in a way that they can run as part of CI pipelines.
  • Ensure high code coverage without compromising the readability and maintainability of the test cases.

Deliverables:

  • Increased unit test coverage with all major code paths covered.
  • Well-written integration tests for key scenarios with WireMock and snapshot testing using Snapshooter.
  • Clear and consistent test results using FluentAssertions for readability.
@guibranco guibranco added enhancement dependencies Pull requests that update a dependency file .NET Pull requests that update .net code documentation Improvements or additions to documentation CI/CD resilience security tests labels Dec 6, 2023
@guibranco guibranco changed the title Add Integration Tests project with WireMock fixture [FEATURE] Add Integration Tests project with WireMock fixture May 15, 2024
@guibranco guibranco changed the title [FEATURE] Add Integration Tests project with WireMock fixture [FEATURE] Increase unit and integration test coverage Sep 13, 2024
@gitauto-ai gitauto-ai bot added the gitauto label Sep 23, 2024
Copy link

gitauto-ai bot commented Sep 23, 2024

Sorry, we have an error. Please try again.

Have feedback or need help?
Feel free to email [email protected].

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI/CD dependencies Pull requests that update a dependency file documentation Improvements or additions to documentation enhancement gitauto .NET Pull requests that update .net code resilience security tests
Projects
None yet
Development

No branches or pull requests

1 participant