Skip to content

Know where to write your tests

Test suites are best written as functions in the same script as the functions they're testing. Typically, they're located at the end of the script for clearer separation. Including the functions in the same script they're testing allows use of private variables, such as to mock actual objects, route logic differently, and write errors elsewhere.

You can use a separate unit test / integration script to trigger the test functions. This typically handles errors internally to make sure all test suites are run. If a test suite fails, an error is bubbled up to the runtime with enough information to identify which test or tests failed. When running tests from CI/CD, it ensures the VoltScript Runtime process exits with an error, which notifies CI/CD that that the build should be aborted.