3 ms·
Every function which returns the current time, should be dependency injected with a 'currentTimeService'. This service, during tests, is injected with your moc
by edejong 10y ago
Every function which returns the current time, should be dependency injected with a 'currentTimeService'. This service, during tests, is injected with your mock implementation, and during production with a simple call to 'new DateTime()' or sth like that.
- hermannj314 10y agoI 100% agree. I've pitched this before (during a code review for something) and was laughed at by the team under some guise of YAGNI / developer gold plating. They honestly thought I was joking. Once I explained the issues mentioned in the article, they still thought it was a waste of time. It takes just a few seconds to implement and makes the code so much easier to test / maintain.
- edejong 10y agoTell them we're currently replaying test scenario's involving thousands of truck routes per day (and around a thousand trucks). This allows us to easily recreate bugs and see the effects of fixes, new algorithms, etc. etc. Couldn't do it with some DI on the whole system and simulated time.