We want to run automated tests on MySQL stored procedures and functions wher the tests compare actual and expected values.
The trouble is, even if we run a fixture script before each test, most of our routines can return different results given the same inputs- we do a lot of datetime stuff that relies on now
. (now
is the built-in function for returning the current datetime.)
How can we "freeze" what now
returns in our test database?
The best solution I can think of is to replace all calls to now
to calls to a custom function. In our prod database, this custom function will just call the built-in now
, and in our dev database it will return a static date.
Is there an easier way, such as something like SET global.CURRENT_TIME = '2015-01-01 00:00:00';
?
Aucun commentaire:
Enregistrer un commentaire