This project uses .NET's built-in testing framework with xUnit and includes code coverage collection using the built-in XPlat Code Coverage collector.
# Run all tests
./build.ps1 Test
# Run tests with code coverage
./build.ps1 Test -Coverage
# Run tests with coverage and open report
./build.ps1 Test -Coverage -OpenReport# Run tests without coverage
dotnet test tests/AGI.Kapster.Tests
# Run tests with coverage
dotnet test tests/AGI.Kapster.Tests --collect:"XPlat Code Coverage"
# Run specific test class
dotnet test tests/AGI.Kapster.Tests --filter "FullyQualifiedName~HotkeyManagerTests"- Unit Tests: Individual component testing
- Integration Tests: Component interaction testing
- Service Tests: Business logic testing
- Command Tests: Undo/redo functionality testing
tests/AGI.Kapster.Tests/
├── Commands/
│ └── CommandTests.cs # Undo/redo command tests
├── Models/
│ ├── AnnotationTests.cs # Annotation model tests
│ └── SettingsTests.cs # Settings model tests
├── Services/
│ ├── HotkeyServiceTests.cs # Hotkey service tests
│ ├── SettingsServiceTests.cs # Settings service tests
│ ├── ExportServiceTests.cs # Export service tests
│ ├── AnnotationServiceTests.cs # Annotation service tests
│ └── OverlayControllerTests.cs # Overlay controller tests
└── TestHelpers/
├── MockHotkeyProvider.cs # Mock hotkey provider
├── MockSettingsService.cs # Mock settings service
├── MockOverlayController.cs # Mock overlay controller
├── TestDataBuilder.cs # Test data builder
├── UIThreadHelper.cs # UI thread helper
└── AvaloniaTestBase.cs # Avalonia test base class
# Generate coverage report
./build.ps1 Test -Coverage
# Coverage files are generated in:
# - artifacts/coverage/coverage.cobertura.xml
# - artifacts/coverage/coverage.opencover.xml- Minimum Coverage: 80%
- Critical Components: 90%+ (Services, Commands)
- UI Components: 70%+ (ViewModels, Views)
The TestDataBuilder class provides convenient methods for creating test data:
// Create test annotation
var annotation = TestDataBuilder.CreateAnnotation()
.WithType(AnnotationType.Arrow)
.WithColor(Color.Red)
.Build();
// Create test settings
var settings = TestDataBuilder.CreateSettings()
.WithHotkey("Alt+A")
.WithDefaultFormat(ImageFormat.Png)
.Build();Mock services are provided for testing:
MockHotkeyProvider: Mock hotkey registrationMockSettingsService: Mock settings persistenceMockOverlayController: Mock overlay management
Tests are automatically run on:
- Push to main: Full test suite
- Pull Requests: Full test suite with coverage
- Release: Full test suite with coverage report
Test results are available in:
- GitHub Actions logs
- Artifacts:
test-results-and-coverage - Coverage reports:
coverage.cobertura.xml
- UI Tests Failing: Ensure Avalonia test base is used
- Hotkey Tests: Use mock hotkey provider
- Settings Tests: Use mock settings service
- Coverage Not Generated: Check XPlat Code Coverage collector
# Run tests in debug mode
dotnet test tests/AGI.Kapster.Tests --configuration Debug
# Run with verbose output
dotnet test tests/AGI.Kapster.Tests --logger "console;verbosity=detailed"- Arrange-Act-Assert: Follow AAA pattern
- Descriptive Names: Use clear test method names
- Single Responsibility: One assertion per test
- Mock Dependencies: Use mock services for isolation
- Group Related Tests: Use test classes for related functionality
- Use Test Categories: Organize tests by type
- Shared Setup: Use constructor or setup methods
- Cleanup: Dispose resources properly
For more detailed testing information, see the individual test files and the project's testing architecture documentation.