67
loading...
This website collects cookies to deliver better user experience
We're happy to welcome @_mvolpato
as the new Tech Editor on our Flutter team!
DateTime.now()
in your code makes unit testing more difficult. You do not know how much time passed between the call to DateTime.now()
and the moment you test its value, so you cannot compare timestamps. Reme Le Hane proposes a solution based on extending DateTime
. I wonder if you can separate the two static methods into two different extensions, so that you can declare the setter only for testing, to avoid accidentally use it in your production code.World
service that you can inject into other classes. This service will provide values like DateTime.now()
in production, or the real value for some sensors, or GPS location. While during testing it can be fully mocked.