This document describes the comprehensive testing approach for Audit.NET, including test organization, integration test infrastructure, execution strategies, and code coverage practices. The testing strategy ensures reliable validation across 45+ assemblies and 376+ classes with 89.4% line coverage.
For information about the CI/CD pipelines that execute these tests, see CI/CD Infrastructure. For details on multi-framework targeting that affects test execution, see Multi-Framework Support. For code quality metrics and analysis, see Code Quality and Coverage.
The test suite is organized into dedicated test projects that correspond to production assemblies:
| Test Project Pattern | Production Assembly | Purpose |
|---|---|---|
Audit.*.UnitTest | Audit.* | Unit and integration tests for specific packages |
test/TestResult/ | N/A | Test execution results and coverage reports |
Each test project targets multiple frameworks to validate cross-platform compatibility:
netcoreapp3.1, net6.0, net462
Sources: .github/workflows/CI-BuildAndTest.yml98-106 test/Audit.AzureCosmos.UnitTest/Audit.AzureCosmos.UnitTest.csproj4
Tests are organized into two primary categories:
Tests use NUnit's [Category] attribute to enable selective test execution:
Integration tests combine categories to indicate requirements:
Sources: test/Audit.AzureCosmos.UnitTest/AzureCosmosTests.cs20-24 test/Audit.Redis.UnitTest/RedisTests.cs13-16 test/Audit.RavenDB.UnitTest/RavenDbDataProviderTests.cs15-18
Tests are filtered during CI execution using category combinations:
Sources: .github/workflows/CI-BuildAndTest.yml214-215 .github/workflows/CI-BuildAndTest.yml52-54
Integration tests rely on 14 containerized services orchestrated via Docker Compose:
The complete service stack is defined in a single compose file:
File: Docker/docker-compose.yml
Key services include:
Sources: Docker/docker-compose.yml1-160
The CI pipeline ensures all services are available before running tests:
Sources: .github/workflows/CI-BuildAndTest.yml127-162
Tests execute across two separate CI jobs to accommodate platform-specific requirements:
Windows Job (build-and-test-windows):
windows-latestMonoIncompatibleLinux Job (build-and-test-linux):
ubuntu-22.04MonoIncompatibleSources: .github/workflows/CI-BuildAndTest.yml17-55 .github/workflows/CI-BuildAndTest.yml57-250
Tests execute with limited parallelization to avoid resource contention:
The -m:1 flag limits parallel execution to avoid port conflicts and resource exhaustion across 14 containerized services.
Sources: .github/workflows/CI-BuildAndTest.yml212-215
Centralized test configuration provides connection strings and service endpoints:
Sources: test/AzureSettings.cs5-27
Tests connect to local services using consistent patterns:
Redis:
test/Audit.Redis.UnitTest/RedisTests.cs18
RavenDB:
test/Audit.RavenDB.UnitTest/RavenDbDataProviderTests.cs20
Azure Cosmos DB:
test/Audit.AzureCosmos.UnitTest/AzureCosmosTests.cs28-36
The test suite achieves comprehensive coverage across the codebase:
| Metric | Value | Details |
|---|---|---|
| Line Coverage | 89.4% | 10,552 of 11,790 coverable lines |
| Branch Coverage | 80% | 3,857 of 4,817 branches |
| Assemblies | 45 | All production packages |
| Classes | 376 | Core and extension classes |
| Files | 330 | Source files analyzed |
Sources: CODE_COVERAGE.md11-18
High-coverage assemblies (>95%):
| Assembly | Line Coverage | Branch Coverage |
|---|---|---|
Audit.FileSystem | 100% | 100% |
Audit.EntityFramework.Identity | 100% | N/A |
Audit.NET.JsonNewtonsoftAdapter | 100% | 97.5% |
Audit.NET.PostgreSql | 99.5% | 93% |
Audit.AzureFunctions | 98.4% | 82.8% |
Audit.NET.Firestore | 98.1% | 88.4% |
Audit.HttpClient | 97.5% | 90.6% |
Audit.MediatR | 97.5% | 77.4% |
Sources: CODE_COVERAGE.md28-199
Coverage reports are generated using reportgenerator:
Results are:
CODE_COVERAGE.mdSources: .github/workflows/CI-BuildAndTest.yml227-229
The coverage report identifies high-complexity methods requiring attention:
| Assembly | Class | Method | Crap Score | Cyclomatic Complexity |
|---|---|---|---|---|
Audit.Wcf.Client | AuditMessageInspector | CreateWcfClientAction | 272 | 16 |
Audit.Wcf.Client | AuditMessageInspector | AfterReceiveReply | 210 | 14 |
Audit.Mvc.Core | AuditAttribute | GetResponseBody | 147 | 36 |
Audit.EntityFramework | DbContextHelper | SetConfig | 100 | 100 |
Sources: CODE_COVERAGE.md21-75
Tests follow a consistent setup/act/assert pattern with proper resource cleanup:
Sources: test/Audit.AzureCosmos.UnitTest/AzureCosmosTests.cs25-83
Async tests follow similar patterns with proper disposal:
Sources: test/Audit.AzureEventHubs.UnitTest/AzureEventHubsTests.cs153-190
Unit tests use Moq to isolate dependencies:
Sources: test/Audit.AzureCosmos.UnitTest/AzureCosmosTests.cs312-348
The Audit.NET testing strategy employs:
This approach ensures reliable validation of core functionality, extension packages, and data provider integrations across multiple .NET versions and platforms.
Refresh this wiki