views:

34

answers:

2

I am working on a ad-related project, in which I need to make sure that our system picks up an advertisement from db at certain interval of time and insert it into our normal service flow.

How would you design test for systems like this so that you don't have to wait 30 mins while confirming that advertisement do occurs at the right time?

+2  A: 

I would decouple the logic which deals with inserting the ad from the timer part, hiding the latter behind an interface (and the same for the DB). Then (using e.g. dependency injection) I can replace the regular timer with a mock timer which fires "immediately" (or after any desired interval) in the unit test, so I can assert that the ad (supplied via the mock DB interface) is inserted properly into the output.

This would be the unit testing part; I would still try to put together some integration test to verify that the whole system works as expected. But after having unit tested the logic thoroughly, the integration test may be shallower, just verifying the few most basic use cases.

Péter Török
A: 

Time dependencies are evil for tests (they harm reproducibility). Try to inject timing depedencies. In your case you could inject/parameterize a time range (e.g. from 30 minutes to near instant).

manuel aldana