Skip to content

[Tests] Replace Custom Integration Test Runner with WebApplicationFactory - #10

Merged
ale206 merged 2 commits into
mainfrom
feature/issue-4-webapplicationfactory-integration-tests
Nov 4, 2026
Merged

ale206 merged 2 commits into
mainfrom
feature/issue-4-webapplicationfactory-integration-tests

Conversation

@ale206

@ale206 ale206 commented Oct 31, 2026 •

Copy link
Copy Markdown
Owner

Resolves #4

Summary of Changes

  • Migrated ModularNet.IntegrationTests to xUnit + WebApplicationFactory<Program>:
    • Removed custom console runner (Program.cs) and converted project to standard test SDK (Microsoft.NET.Sdk) with Microsoft.AspNetCore.Mvc.Testing and xunit.
    • Added ModularNetWebApplicationFactory and IntegrationTestCollection to share the test server instance and optimize execution.
    • Added full template reference integration tests demonstrating best practices:
      • HealthChecksEndpointTests: GET endpoints, typed JSON response deserialization, error handling (500), and dependency substitution via WithWebHostBuilder(builder => builder.ConfigureTestServices(...)).
      • EmailVerifierEndpointTests: POST endpoints with JSON request bodies (PostAsJsonAsync) and boolean responses.
      • AuthEndpointTests: Authentication endpoints covering 200 OK, 201 Created (new vs. existing user), and 401 Unauthorized scenarios.
      • ProtectedEndpointsTests: Verifying endpoints decorated with [Authorize] reject unauthenticated requests with 401 Unauthorized.
      • Added comprehensive README.md in the integration tests project documenting conventions, patterns, and usage for developers starting from this template.
  • CI Pipeline & Code Coverage Integration:
    • Configured coverlet.msbuild and coverlet.collector in ModularNet.IntegrationTests.csproj.
    • Updated .github/workflows/unit-tests.yml to run both Unit Tests and Integration Tests with merged coverage using /p:MergeWith.
    • Solution code coverage increased from 61% to 71% (exceeding the 70% threshold).
  • Application Configuration & Reliability Enhancements:
    • Updated ModularNet.Api/Program.cs to expose public partial class Program { } for WebApplicationFactory.
    • Added thread-safe locking and concurrency handling for Firebase Admin SDK initialization across parallel host contexts.
    • Added connection string null-guard for AddApplicationInsightsTelemetry().
    • Fixed base64 initialization vector in appsettings.json to 16 bytes for valid AES cipher operation.

Verification

  • Solution test run: dotnet test src/ModularNet.sln -> 137 unit tests and 27 integration tests passing (164 total, 0 failed).
  • Merged code coverage: 71%.
  • Adheres strictly to coding-standards.md conventions (xUnit, AAA pattern, no Async suffix on test method names).
  • GitHub Actions CI checks passing.

@ale206
ale206 merged commit 162384f into main Nov 4, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Tests] Evaluate Replacing Custom Integration Test Runner with WebApplicationFactory

1 participant