This directory contains unit tests for the PrettyScreenSHOT application.
- xUnit - Modern, extensible unit testing framework for .NET
- Moq - Mocking library for .NET
- coverlet - Code coverage tool
# Run all tests
dotnet test
# Run tests with verbose output
dotnet test --logger "console;verbosity=detailed"
# Run tests with code coverage
dotnet test /p:CollectCoverage=true /p:CoverletOutputFormat=opencover
# Run specific test class
dotnet test --filter "FullyQualifiedName~SettingsManagerTests"
# Run specific test method
dotnet test --filter "FullyQualifiedName~SettingsManagerTests.Instance_ShouldNotBeNull"- Open Test Explorer (Test > Test Explorer)
- Click "Run All" to run all tests
- Right-click individual tests to run or debug
- Install "C# Dev Kit" extension
- Tests will appear in the Test Explorer sidebar
- Click the play button to run tests
Tests/
├── Services/
│ ├── SettingsManagerTests.cs # Tests for settings management
│ └── SecurityManagerTests.cs # Tests for encryption & security
├── Helpers/
│ └── DebugHelperTests.cs # Tests for debug utilities
└── README.md # This file
Current test coverage focuses on:
- SettingsManager - Configuration persistence and retrieval
- SecurityManager - Encryption key generation and derivation
- DebugHelper - Debug logging utilities
To improve test coverage, consider adding tests for:
- Screenshot capture functionality
- Image processing and editing
- Cloud upload providers
- Video capture manager
- Update system
- Localization helpers
using Xunit;
using PrettyScreenSHOT.Services;
namespace PrettyScreenSHOT.Tests.Services
{
public class YourServiceTests
{
[Fact]
public void YourMethod_WithValidInput_ShouldReturnExpectedResult()
{
// Arrange
var service = new YourService();
var input = "test";
// Act
var result = service.YourMethod(input);
// Assert
Assert.NotNull(result);
Assert.Equal("expected", result);
}
[Theory]
[InlineData("input1", "output1")]
[InlineData("input2", "output2")]
public void YourMethod_WithMultipleInputs_ShouldReturnCorrectOutputs(
string input, string expected)
{
// Arrange
var service = new YourService();
// Act
var result = service.YourMethod(input);
// Assert
Assert.Equal(expected, result);
}
}
}- AAA Pattern - Arrange, Act, Assert
- Descriptive Names - Test names should describe what they test
- One Assert Per Test - Keep tests focused
- Independent Tests - Tests should not depend on each other
- Fast Tests - Unit tests should run quickly
- Cleanup - Restore state after tests (especially with singletons)
Some classes (like SettingsManager) use the Singleton pattern, which makes testing challenging:
- Tests share state through the singleton instance
- Tests include cleanup code to restore original values
- Consider refactoring to use Dependency Injection for better testability
Current tests focus on business logic and services. UI testing for WPF windows requires:
- UI automation frameworks (e.g., FlaUI, WinAppDriver)
- Additional setup and configuration
- Longer test execution times
Tests are automatically run on:
- Every push to any branch
- Every pull request
- Scheduled nightly builds
See .github/workflows/dotnet.yml for CI/CD configuration.
Code coverage reports are generated during CI builds and can be viewed:
- Locally: After running with coverage, check
coverage.opencover.xml - CI: Coverage reports are uploaded as build artifacts
Ensure .NET 10.0 SDK is installed:
dotnet --versionRestore NuGet packages:
dotnet restore- Check for environment-specific dependencies
- Ensure tests don't rely on local file paths
- Verify tests are platform-independent
When adding new features:
- Write tests for new functionality
- Ensure all tests pass locally
- Aim for >70% code coverage
- Update this README if adding new test categories
Last Updated: 2025-11-16 Test Framework: xUnit 2.9.2 Target Framework: .NET 10.0