Skip to content

Latest commit

 

History

History
191 lines (152 loc) · 5.66 KB

File metadata and controls

191 lines (152 loc) · 5.66 KB

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

Coverage Tools

  • 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

  1. HTML Reports: Detailed coverage analysis
  2. Cobertura XML: Standard format for CI/CD
  3. 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

  1. Arrange-Act-Assert: Clear test structure
  2. Single Responsibility: One concept per test
  3. Descriptive Names: Test intent is clear
  4. Edge Case Coverage: Null values, empty collections, boundaries
  5. Error Path Testing: Exception scenarios covered

Coverage Guidelines

  1. Focus on Business Logic: Prioritize critical paths
  2. Mock External Dependencies: Isolate unit under test
  3. Test Both Success and Failure: Happy path and error scenarios
  4. Boundary Value Testing: Min/max values, edge cases
  5. 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

  1. Weekly Coverage Reviews: Track trends and identify gaps
  2. Automated Alerts: Notify on coverage drops
  3. Regular Refactoring: Improve test maintainability
  4. 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.