Testing flow by using date/time references
To run repeatable tests in DataStage, the data flow must always produce the same results from the same inputs. However, using the current date or time in calculations can make the output vary depending on when the job runs. You can design jobs that use the current date in a way that still allows for reliable testing.
Transformer Stages that use system time and date functions
Transformer stages with derivations that use the CurrentDate(),
CurrentTime() or CurrentTimestamp() functions need to be
considered carefully when you design your tests. Unless your calculation requires a specific date
and/or time, consider replacing the following functions: CurrentDate(),
CurrentTime(), and CurrentTimestamp() with calls to the
DSJobStartDate, DSJobStartTime and
DSJobStartTimestamp macros.
Add DSJobStartDate, DSJobStartTime, and
DSJobStartTimestamp (as required) to the parameters clause of the
test Specification when node and set the appropriate date and time values that are
used during Unit Testing.
BeforeToday =
If inPurchases.Purchase_Date < DSJobStartDate Then "Yes" else "No"
EarlierToday =
If inPurchases.Purchase_Date = DSJobStartDate and
inPurchases.Purchase_Time < DSJobStartTime Then "Yes" else "No" in this case, the
when section of your test specification is:{
"given": [
...
],
"when": {
"data_intg_flow_ref": "example_flow_data_intg",
"parameters": {
"DSJobStartDate": "2012-01-15",
"DSJobStartTime": "11:05:01"
}
},
"then": [
...
]
}Exercise caution when setting `DSJobStartTimestamp` in conjunction with either `DSJobStartDate` or `DSJobStartTime` as the DataStage test case capability does not attempt to enforce logical consistency between these parameters. i.e. You could specify conflicting values for these macros which would create a contradictory logical condition. e.g.
```json
{
"when": {
"data_intg_flow_ref": "blah-blah-blah",
"parameters": {
"DSJobStartTimestamp": "2025-02-03 00:00:00",
"DSJobStartDate": "2024-04-05"
"DSJobStartTime": "09:30:00"
}
}
}
```