CtrlK
BlogDocsLog inGet started
Tessl Logo

testland/dotnet-faketime

Wraps .NET's TimeProvider abstraction (System.TimeProvider, introduced .NET 8) and FakeTimeProvider from Microsoft.Extensions.TimeProvider.Testing: SetUtcNow, Advance, AutoAdvanceAmount, CreateTimer, Delay, and the pre-.NET-8 ISystemClock migration path. Use when testing C# or F# code that reads the current time, uses timers, or awaits Task.Delay.

75

Quality

94%

Does it follow best practices?

Run evals on this skill

Adds up to 20 points to the overall score

View guide

SecuritybySnyk

Passed

No findings from the security scan

Overview
Quality
Evals
Security
Files

anti-patterns-and-limitations.mdreferences/

Anti-patterns and limitations

Anti-patterns

Anti-patternWhy it failsFix
DateTime.UtcNow directly in codeNot injectable; test is forced to use wall-clockInject TimeProvider; call _time.GetUtcNow()
DateTimeOffset.UtcNow directly in codeSame problemInject TimeProvider
Static mock of DateTime via Fakes/HarmonyRequires special test runner config or IL rewritingUse DI with TimeProvider
Call SetUtcNow with a value earlier than currentThrows ArgumentOutOfRangeExceptionUse Advance or construct fresh FakeTimeProvider
Forget await Task.Yield() after AdvanceContinuations haven't had a chance to run yetYield or await the completed task
AutoAdvanceAmount in tests needing exact instantsClock shifts unexpectedly between readsSet AutoAdvanceAmount = TimeSpan.Zero (default)
Register TimeProvider.System in test DITests become time-dependent and flakyRegister FakeTimeProvider in test DI setup

Limitations

  • Task.Delay(int) overloads that do NOT accept a TimeProvider still use wall-clock time. Always use the timeProvider.Delay(TimeSpan) extension form.
  • Thread.Sleep is not controlled by FakeTimeProvider; restructure to use await timeProvider.Delay(...) instead.
  • High-frequency GetTimestamp() values are derived from the fake UTC instant, not from Stopwatch. Per learn.microsoft.com/dotnet/api/microsoft.extensions.time.testing.faketimeprovider.timestampfrequency, TimestampFrequency is a fixed value tied to the fake clock.
  • Third-party libraries that call DateTime.UtcNow internally are not affected by FakeTimeProvider; only code that accepts TimeProvider by injection can be controlled this way.
  • No leap-second simulation; see leap-second-reference.

SKILL.md

tile.json