![]() |
![]() |
![]() |
Testing Time sensitive applications How do you test an application with behavior dependent on the date? Either absolute dates like the beginning of a quarter or relative dates like 60 days after some event.
john
Since 60 days is like 5184000 seconds, how about:
Matthew Lock
Maybe create a wrapper function to obtain the time, like "GetTime()" or whatever. When you're in release mode, it returns the "correct" system time. When you're in debug mode, it returns the modified time for testing purposes.
John Rose
I've found that the easiest way to test this kind of thing is to create an interface for a 'time provider' and explicitly pass this provider to the parts of the application that require it. Then, when you want to test things, you can simply (!) pass in a provider that says whatever date you want rather than the actual date... This works best for unit testing...
Len Holgate
What Len is refferring to I believe is known as a mock object (http://www.mockobjects.com/wiki/). This sounds like exactly what you need. During testing, you would replace your real object with your testing object with preset values. Then all other objects within your code would work as if it were getting the real data that you are trying to simulate.
Seeker
Seeker,
Len Holgate
The Mock Object approach sounds good thanks.
john
Or else always supply dates as parameters to your SQL. I had to do this recently on a Sybase->Oracle migration project. To do testing, we needed to be able to test the exisiting app "as of" various dates and times on both systems, and because the reports include various date arithmetic, it was necessary to convert all uses of GETDATE() et al with passed-in parameters, and hack up a mockable function to get the "as of" date and time when running in test mode.
Phillip J. Eby
|