ClinicFlow maintains three dedicated test projects, each targeting a different layer of the application. Together they enforce an 80 % patch coverage gate on every pull request and feed into both Codecov and SonarCloud quality reporting. This page describes the structure, tooling, and conventions of each project and explains how to run them locally.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/0Crazy-0/ClinicFlow/llms.txt
Use this file to discover all available pages before exploring further.
Test Project Overview
ClinicFlow.Domain.Tests
Pure unit tests. No mocks, no database, no I/O. Tests entities, value objects, domain services, and policies in total isolation.
ClinicFlow.Application.Tests
Unit tests with mocked infrastructure. MediatR handlers are tested with Moq-mocked repositories and service interfaces. No real database involved.
ClinicFlow.Infrastructure.Tests
Integration tests. EF Core repositories run against a real PostgreSQL container managed by Testcontainers, reset between tests via Respawn.
Running the Tests
Run all three projects with a single command from the repository root:ClinicFlow.Domain.Tests
Framework: xUnit v3 · Assertions: AwesomeAssertions · Mocking: Moq · Time:Microsoft.Extensions.TimeProvider.Testing
Domain tests verify the core business logic in complete isolation from infrastructure. The directory structure mirrors the domain model:
Shared: EntityTestExtensions
TheEntityTestExtensions static class provides a reflection-based helper for setting private entity IDs in tests — necessary because entity Id properties have no public setter:
ClinicFlow.Application.Tests
Framework: xUnit v3 · Assertions: AwesomeAssertions · Mocking: Moq · Time:Microsoft.Extensions.TimeProvider.Testing
Application tests focus on MediatR command and query handlers. Each handler is instantiated directly with Moq-mocked repository and service dependencies, so no DI container or database is involved.
The directory structure mirrors the application feature folders:
ValidationBehaviorTests in Behaviors/ verify the MediatR pipeline behaviour: it passes through when validation succeeds, and throws ClinicFlow.Application.Exceptions.ValidationException when FluentValidation returns failures.
ClinicFlow.Infrastructure.Tests
Framework: xUnit v3 · Assertions: AwesomeAssertions · Database: Testcontainers (PostgreSQL 17 Alpine) · Reset: Respawn Infrastructure tests verify that EF Core repository implementations produce correct SQL, respect global query filters, and handle edge cases against a real PostgreSQL engine — not an in-memory provider.PostgresFixture
PostgresFixture is an IAsyncLifetime fixture shared across repository test classes via xUnit v3 class fixtures. It manages the full container lifecycle:
await Respawner.ResetAsync(DbConnection) before or after each test to truncate all tables, ensuring test isolation without restarting the container.
CI Pipeline
The CI pipeline is defined in.github/workflows/ci.yml and consists of two jobs:
build job (coverage + quality gates)
build job (coverage + quality gates)
- Checks out the repository with full history (
fetch-depth: 0) for accurate SonarCloud blame data. - Installs JDK 17 and .NET 10.
- Installs
dotnet-sonarscannerglobally. - Begins SonarCloud analysis, pointing at the OpenCover report path.
- Restores and builds the solution.
- Runs all tests with XPlat Code Coverage in OpenCover format.
- Uploads the coverage report to Codecov.
- Ends the SonarCloud analysis, publishing results.
mutation-testing job (Stryker)
mutation-testing job (Stryker)
Runs after
build completes successfully. Installs dotnet-stryker locally to ./tools/.- On
mainpushes: runs Stryker with--version mainto save a new baseline to the Stryker Dashboard. - On pull requests: runs Stryker with
--with-baseline:<base_branch>to compare mutation scores against the saved baseline.
Coverage Policy
Codecov
Thecodecov.yml at the repository root configures the following policy:
domain and application flags track per-layer coverage separately.
Files excluded from coverage analysis:
**/Migrations/**— EF Core migration history**/*.Designer.cs— EF Core migration designer scaffoldingtests/**/*— test project files themselves**/Events/**— domain event records (data carriers, no logic)ClinicFlow.Infrastructure/DependencyInjection.csandClinicFlow.Application/DependencyInjection.cs— DI registration boilerplate
SonarCloud Quality Gate (new code)
| Metric | Required Threshold |
|---|---|
| Coverage on new code | ≥ 80 % |
| Duplicated lines on new code | ≤ 3 % |
| New Bugs | Rating A |
| New Vulnerabilities | Rating A |
| New Security Hotspots | Rating A |
| New Code Smells | Rating A |
ClinicFlow deliberately avoids
[ExcludeFromCodeCoverage] attributes and // NOSONAR comments throughout the Domain and Application layers. These tooling-specific annotations would pollute the domain model. When a coverage check fails on code that contains no testable business logic, the PR author and reviewer verify the false-positive and merge with explicit approval.