How to Test Time Based Features

How do you test time based features?
for ex.: your app has an index of days that passed from last login - is there a better option than changing the machine timestamp? the db date column? etc?

1 Like

Hello Omer!

I recommend working with the developers to have a date or time passed into products rather than have the product read it from the machine. In this manner, you can pass in dates and times to evaluate behavior quickly rather than manipulate machine-level attributes, or wait until some special date or time.

If the product can read date or time from the database or log in, I think you can achieve the same thing suggested in my paragraph above.

Testability is a great topic and one that testers should pursue to their advantage. Testability improvements can reduce testing time and increase confidence in product behavior.


1 Like

During our testing process, we all came across such situations where we need to check some scenarios where time based testing is required.

Some possible cases are as follows:

  • When we have to test expiry of license or agreement.
  • When we need to check the removal of content from server after a certain period of time.
  • When we need to check a event schedule for future listing.

In all above cases, we prefer to do following things:

  1. Change the time on User’s machine.
  2. Change the time on servers.
  3. Another most important and uncommon way is to change the entries in DB and manually provide expiry dates for the same.
  4. The unrealistic way is to create data in advance and wait for the actual time when the event will happen.
  5. Testing with different Timezones (esp if server machine is on different time zone say GST and client machine is on different timezone say PST).

But, in order to delivery best quality assurance services, we always play around with dates and time on server machines to verify the testing scenarios. Hope this information is useful for you.

Are you suggesting the devs hard code dates until testing has finished?

Hello @chris_dabnor!

My apologies if my reply had that interpretation! I don’t mean to suggest developers hard code dates or times ever. Rather, I was attempting to suggest that dates and times become arguments into functions and methods of their products. In this manner during testing, a tester or developer can provide dates/times that help assess product behavior without changing the code.

For example, suppose the function is written this way:

function CalculateTotalToday()

// make calculations

The developer and tester are locked into using today for all the calculations. If the function was written in this way:

function CalculateTotalToday(DateTime dateToUse)

// make calculations

Then, the developer or tester can provide any date for the dateToUse variable.

Does that help?


1 Like

It was me misinterpreting your post, but thank you. I’ve known a value to be hard coded for a quick, and then forgotten about (more support for pairing - for one person to miss is unfortunate, but far less likely for two).

1 Like

For time based features/logic testing you can’t beat using the Time Machine virtual clocks tool by Solution-Soft. Check it out at their website at Very full featured easy to use tool applicable for on-premise or in the Cloud projects. Windows, UNIX and Linux versions, and Docker Container supported as well. Support, if needed, is fantastic too, even for their free evaluations.