Create a TestRunner
The tutorial guides you in creating a TestRunner with two TestSuites and outputs HTML reports.
To create a TestRunner
-
Add the
VoltScriptTesting.vss
script to your project directory - the recommended method is to use dependency management.Tip
The best practice structure for the project directory is the
src
directory for main runnable scripts,libs
directory for VoltScript dependencies, andtest
for unit and integration test runnable scripts. In this structure,VoltScripttesting.vss
would go intolibs
. -
Create a .vss script file in
test
. -
Add
Use "../libs/VoltScriptTesting"
at the top. This navigates up a directory, across to thelibs
directory and down to theVoltScriptTesting.vss
within it. YourUse
statement shouldn't include the .vss suffix.Tip
Best practice options settings to add are
Option Declare
. You can also addOption Public
to make all methods and classes public by default. -
Add a
Sub Initialize
and its closingEnd Sub
statement. -
Add the following code within the
Sub Initialize
:What does the code mean?
Line 1 creates a TestRunner to hold the tests. Lines 2 and 3 create two test suites. Line 6 adds the first TestSuite to the test runner. The following lines add tests.
describe()
is a fluent function that returns thetestSuite1
variable so you can calldescribe()
and the subsequent assertion on the same line. Here, you can just use a basic boolean assertion.Line 11 adds the second TestSuite to the test runner. Line 12 uses an integer assertion. Line 13 asserts that
x
is less than 0.When using other numeric assertions and literal values, you may need to use the relevant conversion function such as
CLng()
. When using assertions that take an expected value, the order is alwaysexpected
as the first parameter andactual
as the second. -
Run the code.
Expected result
The test results will be generated to a unit-test-reports directory in the runtime directory. If running from the command line, this will be the current directory. If running from Visual Studio Code, it will be the directory open in VS Code.
You can find a more thorough example in BasicTester.