In your tests, you may want to run some code before and after each test. In this section, we'll discuss the globally available functions that allow you to do that.
# BEFORE.EACH
If you would like to have certain code run before each test, then add a local sub called:
BEFORE.EACH:
* Do something here
RETURN
This is a good place to initialize variables and set defaults that are passed into an external sub that you are testing so that you do not have to repeat the code for each test.
# AFTER.EACH
If you would like to have certain code run after each test, then add a local sub called:
AFTER.EACH:
* Do some tear down here
RETURN
This might be a good place to clean up any changes that were made to the database or delete any records that might have been created so they don’t interfere with the subsequent tests.
TIP
The BEFORE.EACH and AFTER.EACH subs are optional.
# Cloning files
Sometimes you need to run tests on a file that has real data in it that will effect the outcome of your tests. For example, you might need a test that asserts that you are returning all customers that have the word "design" in it. You might be able to figure out how many it should return today, but tomorrow could be different.
Or maybe you just need to add so much test data to the file that it would be easier to clone and recover than it would be to delete all the new data.
By using MV.TEST.CLONE.FILE and MV.TEST.RECOVER.FILE, you can save the current file to a temporary area so that you can fill it with predictable records. After the test is complete you can recover what was originally in the file and set it back to how it was before the tests ran.
Typically, you would use MV.TEST.CLONE.FILE in your BEFORE.EACH subroutine and then use MV.TEST.RECOVER.FILE in your AFTER.EACH subroutine.
# MV.TEST.CLONE.FILE
CALL MV.TEST.CLONE.FILE(NAME.OF.FILE, ERRORS)
NAME.OF.FILE is the string of the name of the file you would like to clone. For example, if you wanted to clone the PI file then you would pass "PI".
ERRORS is an OUT variable. IF something went wrong with the process the error would be stored in this array.
TIP
Usually after calling MV.TEST.CLONE.FILE you'll want to clear the file using CLEARFILE "NAME OF FILE".
# MV.TEST.RECOVER.FILE
CALL MV.TEST.RECOVER.FILE(NAME.OF.FILE, ERRORS)
NAME.OF.FILE is the string of the name of the file you would like to recover. For example, if you wanted to recover the PI file then you would pass "PI".
WARNING
Recovering only works if you cloned the file first!
ERRORS is an OUT variable. IF something went wrong with the process the error would be stored in this array.
TIP
Usually before calling MV.TEST.RECOVER.FILE you'll want to clear the file using CLEARFILE "NAME OF FILE".
← Assertions Errors →