Debugging Scripts with Assertions
|
Assertions are a debugging technique that helps the developer detect incorrect assumptions as soon as they occur, rather than hundreds of lines later when something finally fails. An assertion can be a simple check to confirm if a condition is true. Simple assertions can be used to verify input values, output results, or current states. An assertion says: “At this point in the script, I expect this condition to be true.” If it isn’t, something has gone wrong. When an assertion fails, the script should inform the developer. At that point there may be options to stop the script, pause to check other values, or ignore the assertion and continue. Assertion structureWe can add an assertion to an existing script like this:
In this example, we are saying "At this point in the script, I expect the layout to be Email Form." If that is true, there is no further action. If false, there is a dialog showing a message of what failed and three buttons – Stop, Pause and Ignore. Stop will halt the script and all other scripts in the stack – stop it dead in its tracks. Pause allows the developer to check other values and states using the Data Viewer on the Current and Watch tabs. Then to cancel or continue as needed. Ignore allows the developer to note the issue but continue the script anyway. The issue with this method is that we have to add a dozen script steps for each assertion we add to the script. There must be a better way. Tomorrow.
|