Vector Test Unit for Visual Studio Code
This extension supports you in creating test units that can be run with CANoe4SW Server Edition or Vector Test Unit Runner.
It interacts with the CAPL, Python, and C# extensions and provides them with type libraries which are necessary to write test implementations.
It also provides editing support for test unit configuration files with file endings vtestunit.yaml
and vtesttree.yaml
.
This includes syntax highlighting, code completion, and validation.
Prerequisites
The Vector Test Unit extension requires a Vector toolset to be installed.
The Vector toolset comes with the commercial product CANoe4SW Server Edition.
It is also part of the freely available Vector Test Unit Runner.
The products CANoe and CANoe4SW are currently not supported.
At least version 17 of the Vector toolset is required.
The currently selected toolset is shown in the status bar.
By default, the latest installed version is used.
To select a specific version, use the command Vector Test Unit: Select Vector toolset
.
The Vector Simulation and Test Environment extension extension is installed automatically as a dependency.
It provides your test unit with the environment from a venvironment.yaml
or venvironment-basic.yaml
configuration file.
The YAML extension is required for editing vtestunit.yaml
and vtesttree.yaml
files.
It will be installed automatically as a dependency, too.
For editing the actual test implementations, please install the respective programming language extensions CAPL, Python, and C#.
Usage
The Vector Test Unit extension discovers all test units in the current workspace by their configuration files *.vtestunit.yaml
.
If there is more than one test unit in the workspace you have to choose one as your active test unit using the command Vector Test Unit: Select active test unit
.
The name of the currently active test unit is shown in the status bar.
The extension will automatically generate type libraries for all test implementation files referenced in the configuration file of the current test unit.
These type libraries allow you to...
- use built-in symbols, functions and namespaces from CANoe4SW Server Edition and Vector Test Unit Runner
- use symbols, functions and namespaces from CAPL libraries, Python packages, and .NET assemblies referenced in the test unit configuration file
If you write tests in C#, you might need to run the command .NET: Open Solution
and choose ActiveVectorSolution.sln
once.
You can manually rebuild type libraries using the commands Vector Test Unit: Generate .NET type libraries
and Vector Test Unit: Generate Python type libraries
.
Example
Please refer to the documentation installed with CANoe4SW Server Edition and Vector Test Unit Runner for details on how to implement test units.
This chapter just provides a short example to facilitate getting started with writing test units for CANoe4SW Server Edition and Vector Test Unit Runner.
A test unit is described using a YAML file with file ending vtestunit.yaml
:
version: 2.0.0
# optional section which contains information about the test unit
test-unit-information:
description: This is an example
# list of all artifacts that belong to the test unit
test-unit-implementation:
- source-file-path: test.can
- source-file-path: test.vtesttree.yaml
- capl-library-path: custom.dll
A test execution tree specifies in which order test cases and test sequences are executed.
It is described using a YAML file with file ending vtesttree.yaml
.
It must be referenced as a source file in the vtestunit.yaml
file.
Test fixtures can be used to structure the test execution tree.
Here is an example:
version: 2.1.0
test-tree:
- capl-test-case: MyTestCase
title: My Test Case Title
- capl-test-sequence: MyTestSequence
- test-fixture: MyTestFixture
elements:
- capl-test-case: MyParameterizedTestCase
description: This is a parameterized test case
params: [1, 2]
The actual test implementation in test.can
may look like follows:
export testcase MyTestCase() {
// TODO
}
export testcase MyParameterizedTestCase(int param1, int param2) {
// TODO
}
export testsequence MyTestSequence() {
// TODO
}