Testing & Coverage Strategy
This document outlines the comprehensive testing strategy for the DKNet Framework to achieve and maintain 99% code coverage across all core library projects.
๐ Coverage Goals
- Core Libraries: 99% line coverage, 95% branch coverage
- EfCore Libraries: 95% line coverage, 90% branch coverage
- Service Libraries: 90% line coverage, 85% branch coverage
- Template Projects: 85% line coverage, 80% branch coverage
๐งช Testing Framework
Test Frameworks Used
- MSTest: Primary testing framework for most projects
- xUnit: Used in template projects and specific scenarios
- Shouldly: Assertion library for fluent assertions
- coverlet.collector: Code coverage collection
- ReportGenerator: Coverage report generation
- Codecov: Coverage reporting and tracking
๐๏ธ Project Structure
Solution/
โโโ Core/
โ โโโ DKNet.Fw.Extensions/ # Core extension methods
โ โโโ Fw.Extensions.Tests/ # 99% coverage target
โโโ EfCore/
โ โโโ DKNet.EfCore.*/ # EF Core libraries
โ โโโ EfCore.*.Tests/ # 95% coverage target
โโโ Services/
โ โโโ DKNet.Svc.*/ # Service libraries
โ โโโ Svc.*.Tests/ # 90% coverage target
โโโ Templates/
โโโ */Tests/ # 85% coverage target
๐ Test Categories
1. Unit Tests
- Scope: Individual methods and classes
- Focus: Business logic, edge cases, error handling
- Coverage: Line, branch, and method coverage
2. Integration Tests
- Scope: Component interactions
- Focus: Database operations, external services
- Coverage: End-to-end workflows
3. Architecture Tests
- Scope: Architectural constraints
- Focus: Dependency rules, naming conventions
- Tool: ArchUnitNET
๐ CI/CD Integration
GitHub Actions Workflows
1. Full Solution Testing (test-and-coverage.yml
)
- Runs on all pushes and PRs
- Tests entire solution
- Generates comprehensive coverage reports
- Uploads to Codecov
- Comments PR with coverage summary
2. Core Libraries Check (core-coverage-check.yml
)
- Runs on Core/EfCore changes only
- Enforces 95% minimum coverage threshold
- Fails build if coverage drops below threshold
- Specialized for critical libraries
Coverage Configuration (coverage.runsettings
)
<Include>
[DKNet*]*
</Include>
<Exclude>
[*.Tests]*
[*Tests]*
[*.TestObjects]*
[*TestDataLayer]*
</Exclude>
๐ Coverage Reporting
Report Types Generated
- HTML Reports: Detailed coverage analysis
- Cobertura XML: Standard format for CI/CD
- JSON Summary: Programmatic access to metrics
Key Metrics Tracked
- Line Coverage: Percentage of code lines executed
- Branch Coverage: Percentage of decision branches taken
- Method Coverage: Percentage of methods called
- Assembly Coverage: Per-assembly breakdown
๐ง Best Practices
Test Design Principles
- Arrange-Act-Assert: Clear test structure
- Single Responsibility: One concept per test
- Descriptive Names: Test intent is clear
- Edge Case Coverage: Null values, empty collections, boundaries
- Error Path Testing: Exception scenarios covered
Coverage Guidelines
- Focus on Business Logic: Prioritize critical paths
- Mock External Dependencies: Isolate unit under test
- Test Both Success and Failure: Happy path and error scenarios
- Boundary Value Testing: Min/max values, edge cases
- Null Reference Testing: Handle null inputs gracefully
Code Quality Gates
- All tests must pass before merge
- Coverage thresholds enforced per project type
- No reduction in coverage allowed
- Architectural rules validated
๐ Examples
Core Extensions Testing
[TestMethod]
public async Task ToListAsync_WithItems_ReturnsCorrectList()
{
// Arrange
var items = new[] { 1, 2, 3, 4, 5 };
var asyncEnumerable = CreateAsyncEnumerable(items);
// Act
var result = await asyncEnumerable.ToListAsync();
// Assert
Assert.IsNotNull(result);
Assert.AreEqual(5, result.Count);
CollectionAssert.AreEqual(items, result.ToArray());
}
Property Extensions Testing
[TestMethod]
public void GetPropertyValueShouldReturnNullForNullObject()
{
// Arrange
var propertyName = "Name";
// Act
var value = ((TestItem3)null).GetPropertyValue(propertyName);
// Assert
Assert.IsNull(value);
}
๐ฏ Current Status
Core Libraries Achievement
- DKNet.Fw.Extensions: 93.1% line coverage โ
- AsyncEnumerableExtensions: 100% coverage โ
- TypeExtensions: Significantly improved โ
- PropertyExtensions: Comprehensive coverage โ
- EnumExtensions: Enhanced with edge cases โ
Recent Improvements
- Added 21 new comprehensive unit tests
- Improved coverage from 85.2% to 93.1%
- Enhanced GitHub Actions automation
- Better coverage reporting and visualization
๐ Continuous Improvement
Monitoring & Maintenance
- Weekly Coverage Reviews: Track trends and identify gaps
- Automated Alerts: Notify on coverage drops
- Regular Refactoring: Improve test maintainability
- Performance Monitoring: Ensure test suite efficiency
Future Enhancements
- Mutation testing for test quality validation
- Performance benchmarking integration
- Visual coverage trend analysis
- Automated test generation for edge cases
Note: This testing strategy ensures the DKNet Framework maintains high quality standards while enabling rapid development and confident deployment of new features.