How to Test Time Based Features


(Omer) #1

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?


(Joe) #2

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.

Joe


(Vishal Dutt) #3

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.


(christian dabnor) #4

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


(Joe) #5

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()
{
today=Now()

// 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)
{
today=dateToUse

// make calculations
}

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

Does that help?

Joe


(christian dabnor) #6

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).