-
Notifications
You must be signed in to change notification settings - Fork 0
Testing Strategy
Tests use xUnit with coverlet for coverage. The design pays off here: because Core's only
side-effect boundary is IInputSynthesizer and time is injected via TimeProvider, the engine is
fully testable without touching Windows, and the ViewModel is testable without the WinUI runtime.
Run everything with:
just test # mise x -- dotnet test KeepPressing.slnxTests the engine and helpers against fakes, with deterministic virtual time:
-
FakeInputSynthesizerrecords an ordered log ofPress/Releaseactions, implementsTapasPress→Release, supports fault injection (ThrowOnTap), and exposesWaitForCountAsyncto await a given number of events (timer continuations run on the thread pool afterAdvance, so you wait for them rather than asserting synchronously). -
FakeTimeProviderdrivesPeriodicTimerso repeat timing is exact and instant — no real delays. - Coverage focus: the state machine (Idle↔Running), the first immediate press in Repeat (the
do/whilesends one tap before the first tick), the Up guarantee in Hold (release on cancel and on fault), andVirtualScreencoordinate normalization.
Tests MainPageViewModel and SpecBuilder with a set of fakes in Fakes.cs:
| Fake | Stands in for | Purpose |
|---|---|---|
FakeHotkeyListener |
IHotkeyListener |
Records registrations, can reject specific VKs (conflict), can raise Pressed
|
SynchronousUiDispatcher |
IUiDispatcher |
Runs marshaled actions inline so tests stay synchronous |
FakeCursorLocator |
ICursorLocator |
Returns a fixed cursor position |
RecordingInputSynthesizer |
IInputSynthesizer |
Captures the spec the VM actually built |
FakeLocalizer |
ILocalizer |
Echoes keys/args so tests need no PRI resources |
Coverage focus: hotkey registration and conflict handling (reject a VK → error surfaced, selection
reverts and re-registers the previous key), command enablement logic (e.g. start disabled until a
key is set), and SpecBuilder validation (NaN interval, missing fixed coordinates, missing key).
- Domain behavior →
KeepPressing.Core.Tests, withFakeInputSynthesizer+FakeTimeProvider. UseWaitForCountAsyncinstead of sleeping. - UI/translation behavior →
KeepPressing.App.Tests, with theFakes.csdoubles andSynchronousUiDispatcher. - Keep timing deterministic — never depend on wall-clock delays.
Related: Architecture · Domain Model & ADTs · Building & Tasks
KeepPressing · Releases · Issues · Licensed under Apache-2.0
Getting started
User guide
Developer guide