-
Notifications
You must be signed in to change notification settings - Fork 1
Helpful Tips
Jason Mace edited this page Oct 18, 2018
·
2 revisions
If the date is inconsequential, the best way to deal with it is to add it to the list of columns to ignore. There are times, though, when the date matters and you need to have a way of generating reliable, predictable values.
One method is to create a wrapper function, as shown below.
ALTER FUNCTION dbo.getDateWrapper()
RETURNS DATETIME
BEGIN
RETURN GETDATE()
END
GOThis can be used in your procedure or function like so:
-- Call it once and store the result so T-SQL doesn't call it for each row
DECLARE @date DATETIME = dbo.getDateWrapper()
-- ...
SELECT @dateThis can then be mocked in JUTS:
-- Mock the date function
EXEC juts.addCommandToScenario
@scenarioId = @scenarioId
, @command = 'ALTER FUNCTION dbo.getDateWrapper() RETURNS DATE BEGIN RETURN ''20200101'' END'As expected, the wrapper function will be rolled back at the end of the test.