Touch Develop retirement postponed until June 22, 2019. Sign-in and access to cloud assets to be removed on May 23, 2018.Learn More..


testing

You can use tests to find bugs and ensure the quality of your code. To create a test, simply create a new action and check the test action checkbox in the properties for the action. Note that test actions cannot have any input arguments. You can mark test actions as private.
private test function
test
()
...
end function

running tests

You can run tests individually or all at once.
  • To run a single test click the test button next to the test you want to run. When running a single test, the debugger is automatically turned on.
  • To run all tests at once click the run tests button. When running all tests, the wall is not visible and the debugger is disabled.

assertions

The contract service is very handy for testing. It evaluates whether a particular condition is true, and stops execution on each false result.
  • contract can be used in any action, not just tests.
  • contract does not work in published scripts.

example

The following example demonstrates using contract→assert to check whether the square() action is returning the correct value. If square() returns the wrong value, program execution is halted and the specified message is displayed.
private test function
test square
()
var r :=  square(2)
contract → assert(r = 2, "The square action has failed.")
end function
You can use contract→requires to check a condition on input parameters, as shown here.
function
square
(
p : Number)
returns (
r : Number)
do
contract → requires(p > 0, "p must be a positive value")
r := p * p
contract → assert(r > 0, "r must be a positive value")
end function