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.vssscript to your project directory - the recommended method is to use dependency management.Tip
The best practice structure for the project directory is the
srcdirectory for main runnable scripts,libsdirectory for VoltScript dependencies, andtestfor unit and integration test runnable scripts. In this structure,VoltScripttesting.vsswould go intolibs. -
Create a .vss script file in
test. -
Add
Use "../libs/VoltScriptTesting"at the top. This navigates up a directory, across to thelibsdirectory and down to theVoltScriptTesting.vsswithin it. YourUsestatement shouldn't include the .vss suffix.Tip
Best practice options settings to add are
Option Declare. You can also addOption Publicto make all methods and classes public by default. -
Add a
Sub Initializeand its closingEnd Substatement. -
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 thetestSuite1variable 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
xis 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 alwaysexpectedas the first parameter andactualas 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.