fake-clock-testing
Installation
SKILL.md
fake-clock-testing
Overview
Tests that read the real clock flake at midnight, on DST transitions, and on slow CI runners. The fix is always the same discipline, whatever the language: replace the clock the code under test reads, drive it explicitly, and restore it afterwards. Two mechanism families exist:
| Family | How it works | Libraries |
|---|---|---|
| Injection | Production code takes a clock dependency; tests pass a fake | java.time.Clock / InstantSource (JVM), TimeProvider / FakeTimeProvider (.NET) |
| Patching | The library rewrites the runtime's time APIs in test scope | freezegun (Python), Jest fake timers + Sinon @sinonjs/fake-timers (JS), timecop (Ruby), libfaketime (libc interception, any binary) |
Injection needs source control of the code under test but has no global state; patching works on unmodified code but must be scoped and torn down per test.