VectorCAST Test ExplorerThis extension supports interacting with VectorCAST/C++ test environments using the VS Code Test Explorer, as well as displaying code coverage as a gutter decoration in C/C++ source editors. PrerequisitesYou must have a VectorCAST version 21 or newer installed and licensed, and the installation directory must be:
During extension activation, the prerequisites will be checked, and any errors reported in the VectorCAST Test Explorer output panel. You can check if VectorCAST is on your path by:
You can check if VECTORCAST_DIR is set properly by:
Additionally, if you are using a version of VectorCAST that is older than VectorCAST 23, you must manually add the crc32 utilities to your VectorCAST install directory from this GitHub repo: https://github.com/vectorgrp/vector-vcast-crc32. UsageThis extension extends the VS Code Test Explorer. To use the extension, open a folder that contains one or more VectorCAST test environments, and click on the Test Explorer "Flask" icon in the activity bar to open the VS Code Test Explorer pane. Within a few seconds a list of VectorCAST test environments will be displayed with a list of units, functions, and tests for each environment. If your workspace does not contain any VectorCAST test environments, you can start testing by right clicking on any C or C++ file in the explorer tree, and choosing "Create VectorCAST Environment". This action will automatically activate the extension, and start the environment build process. A final option to manually activate the extension without building an environment, is to choose the "VectorCAST Test Explorer: Configure" from the command palette. (Use: ctrl-shift-p or View->Command Palette to access). Once the extension is activated, you will be able to use the following features: FeaturesMany of the features implemented by this extension are common to the VS Code test explorer. The following sub-sections focus on features that are unique to the VectorCAST Test Explorer. The VectorCAST Configuration FileBefore you can build a test environment, you must create a VectorCAST configuration file which allows you to choose the compiler you're using, default search directories, and many other tool options. The easiest way to do this is to set the extension option: "Configuration Location" to point to an existing CCAST_.CFG file. To make setting this value easier, you may right click on any existing CCAST_.CFG file and choose: "Set as VectorCAST Configuration File" If this option is not set, and you attempt to build an environment, the extension will automatically open the VectorCAST graphical option editor. Creating a New Test EnvironmentTo create a new test environment, simply select one or more C/C++ files (.c, .cpp, .cxx, .cc) from the File Explorer view, right click, and select: Create VectorCAST Environment. The new test environment will be created in the location set via the extension setting: "Unit Test Location". By default, this settings value is "./unitTests" which means that the environment will be created in the "./unitTests" sub-directory of the directory containing the source file. Coded Testing SupportIf you would like to use the Coded Tests feature (VectorCAST 24 and newer), you must set the "Enable Coded Tests" extension option before building an environment. Test Explorer Icons
The Test TreeThe VectorCAST Test Tree contains a hierarchy of nodes for each VectorCAST Test Environment. The top-level node will indicate the relative path from the workspace root to the environment. The subsequent levels show units, functions, and test cases. Test Tree Context MenusEnvironment node context menuThe right click context menu for Environment nodes, has a VectorCAST sub-menu with the following commands:
Unit, function, and test node context menuThe right click menu for unit, function, and test nodes has a VectorCAST sub-menu with the following commands:
Coded test context menuIf an environment was built with Coded Testing Support enabled (VectorCAST 24 and newer) The right click context menu for all Coded Test nodes will have a VectorCAST sub-menu with the following commands:
The "Flask+" IconSpecial "Flask+" icons are displayed in the margin of the text editor for all VectorCAST testable functions. This right click menu provides the ability to create a new test script, or generate Basis Path or ATG tests for a single function. Creating a New Test ScriptTo create a new test, right click on a unit or function node and choose: "New Test Script" from the VectorCAST right-click context menu, or right clicking on the "flask+" icon, and choose: "New Test Script" Auto-generated Test CasesTo insert Basis Path or ATG test cases for an environment, unit, or function, click on the appropriate node, and choose: "Insert Basis Path Tests" or "Insert ATG Tests", or right click the "flask+" icon and choose "Generate Basis Path Tests" or "Generate ATG Tests". In both cases, a progress dialog will be display as the test cases are computed. Note that the "ATG tests" menu is only available if you are using version of VectorCAST 23sp5 and higher. Editing an Existing Test ScriptTo edit an existing test script, right click on an environment, unit, function, or test node and choose: "Edit Test Script" from the VectorCAST right-click context menu Test Script Editing FeaturesThe extension provides Language Sensitive Editing (LSE) features to support the VectorCAST Test Script syntax. The LSE features are activated, whenever the extension is active and a file with a '.tst' extension is opened in the editor. You can easily create the framework for a new test by using the 'new' snippet. Just type 'vcast-test' anywhere in the '.tst' file, and then return, and the minimum commands to create a test will be inserted To add a single script line, type TEST. and a list of all possible commands will be displayed. A very helpful LSE features is auto-completion for TEST.VALUE and TEST.EXPECTED lines.
Type TEST.VALUE:, to see a list of all possible unit names, then a dot to see a list of The LSE features make it quick and intuitive to create new VectorCAST test scripts. Test Script ImportingWhen editing a test script file, a "Load Test Script into Environment" right click menu item is available in the editor window to load the test script into the VectorCAST test environment. If there are unsaved changes, the load command will also perform a save. Coded Test Include FileCoded test files require an include like this: #include <vunit/vunit.h> so for IntelliSense editing to work nicely for coded test files, you must add an include path to for this file to your workspace. IntelliSense include paths can most easily be added to the appropriate c_cpp_properties.json file. If you enable the VectorCAST test explorer and configure it with a VectorCAST version that supports coded testing, the extension will check for the existence of the correct include path and prompt you to add it if it is not found. You can create a new c_cpp_properties file, by using the: 'C/C++: Edit Configurations (JSON)' command, and can easily add the required include path, by right clicking on a new or existing file, and choosing: "VectorCAST: Add Coded Test Include Path" Here is an example a c_cpp_properties.json file with the vUnit include path added:
Editing a Coded TestMuch of what you will do with Coded Test editing will use normal C++ syntax and as a result will be supported by the C/C++ language extension. Because of the more involved syntax required for mocking the extension supports some IntelliSense features dedicated to mocking. Specifically, to easily define a mock for a function you simply need to use the auto-complete feature for mocking to select the file (unit) and function, and the extension will do the rest. To trigger this feature, just type: "// vmock ", and the extension will display a list of units that are valid for the environment associated with the current coded test file. After the unit is selected, typing another space will display all possible functions and methods that can be stubbed. As is common with IntelliSense, if you type a few characters after the list is displayed, the editor will filter to choices containing those characters. After selecting a function or method to be stubbed, the editor will provide the complete stub declaration as well as the "usage line" hint for what you need to include in your VTEST. Assume you have a file called: "myFile.cpp" and a function called: "foo()" defined like this:
Proceed as follows when creating a coded test:
Which will look like this:
You can then edit the mock logic to insert a hard-coded return of 100 and use the Usage hint to create a test like this:
Note: This feature is only supported for tool and environment version that are newer than VectorCAST 24 sp3. If you type "// vmock" in a file associated with ane environment that was built with an older version of VectorCAST, you will get the diagnostic message: "This environment does not support mocks, no auto-completion is available", Note: The extension will has a code snippet for the : "auto vmock_session = ..." line, so if you simply type "vsession" it will generate the correct variable declaration Code Coverage AnnotationsBy default, the extension will display VectorCAST coverage data using green and red bars in the gutter of any file that has code coverage data, and will show the x/y code coverage % in the status bar. This feature can be toggled ON and OFF using the command: "VectorCAST Test Explorer: Toggle coverage annotations" from the command palette, or using the shortcut ctrl-shift-c. Note: partial coverage will not be shown, and for MC/DC, only the top level condition will be annotated Test Case DebuggingThe extension supports debugging VectorCAST tests via the right click Test Context menu or icon. Debugging requires a special launch configuration called: VectorCAST Harness Debug, which can be installed by right clicking on any existing launch.json file in your workspace, and choosing: "VectorCAST: Add Launch Config" When you select "debug" for a test, the extension will prepare the VectorCAST environment for debugging, open the VectorCAST version of the source file for the unit under test, and scroll the file to the start of the function being tested. You then simply need to set a breakpoint and use F5 to start the debugger. VectorCAST Data ServerIntroductionMuch of the functionality of the extension requires issuing commands to the VectorCAST command line interface (clicast) or requesting data from the VectorCAST data API via the Vector Python Interpreter (vpython). To alleviate the "startup cost" for these interactions the extension includes an optional data server that responds to TCP requests and executes the required command or returns the needed data, without incurring the overhead of application initialization and license checkout. Initialization ProcessingThe use of the data server is controlled by the "Use Data Server" setting which is defaulted to "On". When the extension starts, and the setting is on, it will check if the VectorCAST installation supports "server mode" (vc24sp5 and higher), start a data server if it does, and display a "vDataServer On" button in the status bar. If the setting value is "Off", or if the VectorCAST installation does not support "server mode" then no status button will be displayed. Activation and Deactivation after InitializationThere are several actions that will cause the Data Server to be stopped or started after extension startup, based on the following user actions:
Long running commandsBecause VectorCAST does not support multiple processes accessing a single environment, the underlying data server is single threaded. This means that in the case of a long running process, like a test execution, other server requests will be queued and not executed until the long running process has completed. The only user impact of this occurs if you start the execution of a long-running test, and before
it finishes, attempt to use the IntelliSense features for test script or coded test editing. If this is a nuisance, you can simply disable the server in this case. Error Handling and ReportingIf the Data Server encounters a networking or internal error, the extension will stop the Data Server and fall back to non-server mode. The vDataServer Status Bar button will display "vDataServer Off" and can be used to re-start the Data Server. Server LogWhen the Data Server starts, it will create a log file in the workspace to log each command it receives. You can open this log file by using the "VectorCAST Test Explorer: Open Data Server log" command in the Command Palette. Miscellaneous FeaturesIf you would like to exclude the VectorCAST internal files from your file explorer view, you can do so by right clicking on the settings.json for the workspace and choosing: 'VectorCAST: Add Filter for Environment Files'. This will add the patterns for all of the temporary VectorCAST files to the 'files.exclude' list. To open and close the extension-specific message panel, use ctrl-shift-v Extension CommandsThis extension contributes the following commands:
Extension SettingsThis extension contributes the following general settings:
And the following build settings If you change a build setting, and rebuild an existing environment, the new build settings will be used to update that environment. For example, if you change the coverage kind to "Statement+Branch" that coverage kind will be active after the re-build action.
Known Issues
ContributingThis extension is open-source, released under the MIT license, and we welcome your contributions.
LicenseCopyright (c) Vector Informatik GmbH Licensed under the MIT license |