Test Types
PowerToys uses multiple types of testing to ensure quality:| Test Type | Purpose | Tools | Requirements |
|---|---|---|---|
| Unit Tests | Test individual functions and classes | MSTest, xUnit | Standard dev environment |
| UI Tests | Test user interface and interactions | WinAppDriver, MSTest | WinAppDriver v1.2.1, Developer Mode |
| Fuzz Tests | Find security vulnerabilities | OneFuzz, SharpFuzz | .NET 8, OneFuzz service |
Unit Tests
Finding Unit Tests
Unit test projects follow naming conventions:FancyZonesUnitTestsAdvancedPasteUnitTestsPowerLauncherUnitTests
- Same folder as the module:
src/modules/<Module>/Tests/ - Sibling folder:
src/modules/<Module>/<Module>UnitTests/ - Separate test directory:
src/tests/<Module>UnitTests/
Running Unit Tests
Using Visual Studio Test Explorer
-
Open Test Explorer:
- Menu: Test > Test Explorer
- Keyboard:
Ctrl+E, T
-
Build the test project first:
- Wait for exit code 0 (build success)
-
Run tests in Test Explorer:
- Click Run All to run all tests
- Right-click specific test to run individually
- Use search/filter to find specific tests
Using vstest.console.exe
Run tests from command line:Writing Unit Tests
C# Unit Tests
Create test class with MSTest:C++ Unit Tests
Using Microsoft Native Unit Test Framework:UI Tests
Prerequisites
-
Install WinAppDriver v1.2.1:
- Download from WinAppDriver releases
- Install to default location:
C:\Program Files (x86)\Windows Application Driver
-
Enable Developer Mode:
- Settings > Update & Security > For developers
- Select “Developer mode”
- Close PowerToys before running UI tests
Running UI Tests
-
Build PowerToys solution:
-
Build UI test project:
-
Open Test Explorer (
Ctrl+E, T) - Run UI tests from Test Explorer
UI Test Project Structure
Follow the naming convention:src/modules/Hosts/Tests/Hosts-UITests/
Project File Template
Writing UI Tests
Inherit fromUITestBase class:
UI Test Scope Options
WindowSize.Small_VerticalWindowSize.LargeWindowSize.Maximized
Common UI Test Patterns
Finding Elements
Interacting with Elements
Visual Assertions
UI Test Pipeline
UI tests run automatically in the build pipeline: Pipeline URL: https://microsoft.visualstudio.com/Dart/_build?definitionId=161438 Pipeline options:Fuzz Tests
Fuzz testing identifies security vulnerabilities by providing random/malformed input.When to Use Fuzz Tests
Required for modules that:- Handle file I/O (reading, writing, parsing files)
- Process user input (text, commands, data)
- Parse external data formats (JSON, XML, images, etc.)
- Interface with external APIs or services
Fuzz Test Implementation
C# Fuzz Tests with SharpFuzz
-
Add NuGet packages:
-
Create fuzz target:
C++ Fuzz Tests with libFuzzer
Running Fuzz Tests Locally
OneFuzz Integration
PowerToys integrates with Microsoft’s OneFuzz service for continuous fuzzing:- Runs automatically in CI/CD pipeline
- Generates crash reports for security team
- Provides coverage metrics
- See Fuzzing Testing docs
Test Requirements
When to Update Tests
Always update tests when:- Adding new functionality
- Changing existing behavior
- Fixing bugs
- Refactoring code
- Comment-only changes
- Documentation updates
- String/resource changes (with justification)
- Whitespace/formatting fixes
Test Coverage Expectations
- New modules must have unit tests
- UI-based modules should have UI tests
- File/input handling modules must have fuzz tests
- Bug fixes should include regression tests
Testing Discipline
Before Opening a PR
- Build succeeds with exit code 0
- All existing tests pass locally
- New tests added for new functionality
- Tests pass in Test Explorer
- Fuzz tests implemented if handling file I/O or user input
Test Checklist
- Unit tests written for new code
- UI tests written for UI changes (if applicable)
- Fuzz tests written for file/input handling (if applicable)
- All tests pass locally
- Tests documented with clear names
- Edge cases covered
- Exception handling tested
- Performance considered for test execution time
Special Testing Requirements
Multi-Monitor Testing
Utilities requiring multi-monitor testing:- FancyZones
- Display Fuser
- Mouse Jump
- 2+ monitors with different resolutions
- Different DPI settings (100%, 125%, 150%, 200%)
- Primary monitor on left/right
- Vertical arrangements
- Monitor disconnect/reconnect
Multi-Computer Testing
Mouse Without Borders:- Requires 2+ physical computers
- Cannot be adequately tested with VMs
- Test across different Windows versions
Elevation Testing
Test both scenarios:- PowerToys running as normal user
- PowerToys running elevated (administrator)
Debugging Test Failures
Test Explorer Debugging
- Right-click test in Test Explorer
- Select Debug Selected Tests
- Breakpoints will be hit during test execution
Test Output
View test output in Test Explorer:- Select failed test
- Click “Open additional output for this result” link
- Review stack traces and error messages
UI Test Debugging
Next Steps
Building
Build PowerToys from source
Debugging
Debug PowerToys modules effectively
Coding Style
Follow PowerToys coding standards
Creating New Utility
Create a new PowerToys utility