Anchoring Tests
Anchoring tests means to fix the test to run on a particular date or period. Take the following test for example, which puts schedules and punches on a Sunday and Monday in the current week:
Assuming the week is from Sunday to Saturday, if the test is run on November 15th (a Tuesday), then Sunday and Monday will represent November 13th and November 14th, respectively. If the test is run on December 8th (a Thursday), then Sunday and Monday will represent December 4th and December 5th, respectively.
Hence, the dates represented by the test change over time. This is all well and good until we get to a holiday week, such as Christmas Day, which falls on a Sunday in 2022. Most customers pay Holiday Worked for hours worked on a holiday, and the above test will likely fail when Sunday represents December 25th.
To avoid this issue, anchor the test to prevent it from representing different dates over time. This can be done by using the action: Today is day number <Day> in the month of <Month>.
Now, whenever this test is run, it will set Today to November 13th and use Sunday and Monday that fall in the week of November 13th. Hence, the test will always represent the dates of November 13th and November 14th.
Tip: When deciding which anchor date to use, consider your THEN section. Tests should validate the same date or period on every run, which will guide you in determining the anchor date.
The following actions can be used to anchor a test i.e., they resolve to a specific day in the year:
- Today is day number <Day> in the month of <Month>
- Today is <Holiday Name> holiday
- Today is last year <Holiday Name> holiday
- Today is the first day in the current year
- Today is the last day in the current year
- Today is the last day in the month of <Month>
Note: You cannot use multiple “Today” actions in the GIVEN. If you do, TestAssure will use the last “Today” action for the test.