TimeProvider in .NET8, the solution to flaky tests with DateTime.Now issues
If you're still using DateTime.Now in your .NET tests, you're building on quicksand. Flaky time-dependent tests are some of the most frustrating issues—they pass locally, fail randomly in CI/CD, and destroy confidence in your deployment pipeline. Good news, .NET 8 brings us TimeProvider to solve this problem. This isn't just another abstraction—it's Microsoft's answer to a problem and baked directly into the framework to make time-dependent code reliably testable.
6m read