Simulating the passing of time in unittesting

后端 未结 3 1977
醉话见心
醉话见心 2021-02-04 03:25

I\'ve built a paywalled CMS + invoicing system for a client and I need to get more stringent with my testing.

I keep all my data in a Django ORM and have a bunch of Cele

3条回答
  •  不知归路
    2021-02-04 03:56

    Without the use of a special mock library, I propose to prepare the code for being in mock-up-mode (probably by a global variable). In mock-up-mode instead of calling the normal time-function (like time.time() or whatever) you could call a mock-up time-function which returns whatever you need in your special case.

    I would vote down for changing the system time. That does not seem like a unit test but rather like a functional test as it cannot be done in parallel to anything else on that machine.

提交回复
热议问题