vkhorikov/AutoBuyer

How to run tests in parallel with a static SystemDateTime class

ricksecretin opened this issue · 1 comments

Hey,

Great course about unit testing!

At the end of the course you say that you can use a static SystemDateTime class to overcome the DateTime.Now issue.

Imagine having the following scenario:
Some business requirement is only active on weekend days and another one only on working days

You can call SystemDateTime.Init(() => DateTime.Now) only once. Not per test because they will override the value.

This would mean your tests will have different outcomes depending on the day you run them.
How would you be able to run your tests in parallel?

I don't recommend this approach anymore. It's best to inject time directly, either as a service or a plain value.