Unit Test Configuration (DATAFLOW Code)
This Reference Article has been written for Version 2.1 of the DATAFLOW Software. For Previous Releases use the version selection in the navigation bar at the top of this page.
This Tab is part of Build Configuration Page in the Project Settings dialog.
Tab Description
The Unit Test Page in the Build Configuration is used to configure the unit test code generator for this Build Configuration. This includes fine configuration of the path certain unit test artifacts will be generated to. In addition, the file headers for all generated unit test files can be customized.
See the C++ Code Generation article for an overview on code generation.
Tab Actions
This tab does not provide any special actions.
Tab Groups
The page shows the following groups in Advanced mode:
- Test Code
- Test Paths
- Test Case Categories (A)
For each group, if an option is only shown in advanced mode, it will be marked with (A).
Test Code Group
Test Framework |
This field defines the test framework used to run the generated test code. In V2.0 the only option is MS Test. |
Generate Component Tests |
When this field is checked, the code generator will generated unit test code for all generated components. This include active parts, active interrupts and active containers. |
Generate Data Type Tests |
When this field is checked, the code generator will generate unit test code for all generated data types (see Generator configuration). This includes protocols, structs and custom types. |
Generate Custom Test Base Class |
When this field is checked, a TestBase.cpp file is generated. This can be used to clean up static mocks between each test case and is recommended to be enabled. |
Overwrite AP Test Cases (A) |
When this field is checked, the code generator will overwrite all existing Active part and active interrupt test files. This will overwrite user code. When the field is not checked, any existing user code file will be preserved. Tests for active containers and data types is always overwritten because no user code shall be added to these. |
Test File Template (A) |
This field allows to define the file header for all generated unit test files. To edit, click the [...] button on the right of the field. This shows a dialog to edit the header. All available placeholders are shown. These will be replaced by the code generator. |
In this group, the target test framework must be selected. For V2.1 only MS Test is supported.
The generation of tests for components and data types can be enabled independent of each other. If none is enabled, no unit test code will be generated.
To generate a custom test base class that allows to perform reset of static mocks such as HAL mocks, the 'Generate Custom Test Bae Class' can be enabled.
If 'Overwrite AP Test Cases' is enabled, all unit test files already existing will be overwritten. If not checked, unit tests for active parts and active interrupts will not be overwritten to preserve user code. Warning: This will override all user defined code in these files.
The given file header will be used for all generated unit test files.
Test Paths Group
Root Path |
This field defines the root path for all generated test code of this build configuration. This path must not overlap with any other build configuration in this project or solution to avoid code to be overwritten or deleted by the code generator. |
Clear Output Directory |
This will delete all file in the root path prior to code generation. |
Components (A) |
This field defines the sub folder for all component test code. This includes active parts, active interrupts and active containers. The generated files will be placed in sub folders based on the namespace of the component. |
Data Types (A) |
This field defines the sub folder for all data type test code. This includes protocols, structs and custom types. The generated files will be placed in sub folders based on the namespace of the data type (type groups). |
In this group, the root path for all generated unit tests can be configured.
NOTE: The configured folder must not overlap with any other output folder for this or any other build configuration.
When 'Clear Output Directory' is checked, all contents of the folder and all its sub-folders will be erased before code is generated. Warning: This will delete all user defined code in these folder and all sub-folders.
To place tests for components and/or unit tests in a sub folder, it can be set in the given field. The path is added to the root path. If the field is empty, the root path will be used.
There will be sub folders generated inside the folder (root+ specific path) if the component/type is located in a sub namespace.
Test Categories Group (A)
Protocol (A) |
For each type of unit test, the test category can be defined. This will be written to the attribute of each unit test method of the given type. |
Struct (A) |
For each type of unit test, the test category can be defined. This will be written to the attribute of each unit test method of the given type. |
Custom Type (A) |
For each type of unit test, the test category can be defined. This will be written to the attribute of each unit test method of the given type. |
Buffer (A) |
For each type of unit test, the test category can be defined. This will be written to the attribute of each unit test method of the given type. |
Active Part (A) |
For each type of unit test, the test category can be defined. This will be written to the attribute of each unit test method of the given type. |
Active Interrupt (A) |
For each type of unit test, the test category can be defined. This will be written to the attribute of each unit test method of the given type. |
Active Container (A) |
For each type of unit test, the test category can be defined. This will be written to the attribute of each unit test method of the given type. |
NOTE: This is only supported for the MS Test framework.
In this group, the category generated into the attribute for each test case can be defined independent for all generated tests.
If this is not used, the defaults can be left unchanged.
Generated Unit Tests
The code generator can generate unit test for the following artifacts:
- Components
- Active Container
- Active Part
- Active Interrupt
- Data Types
- Protocol
- Custom Type
- Struct
- Buffer
Active Container |
The unit test for an Active Container contains the following test cases: test<Name>APC_IsInitialized Generated once per active container. Asserts that all child components of the container are initialized when the container is initialized. test<Name>APC_IsStarted Generated once per active container. Asserts that all child components of the container are started when the container is started. test<Name>APC_InternalConnections_Static Generated once per active container. Asserts that all channels inside the container are connected to the ports defined in the DATAFLOW Designer model. test<Name>APC_ExternalPorts_Static Generated once per active container. Asserts that all external ports of the container are forwarded to the internal ports defined in the the DATAFLOW Designer model. |
History: Added in V1.0 |
Active Part |
The unit test for an Active Part contains the following test cases: test<Name>AP_Priority
Generated once per active part. Asserts that the Active Part has the runtime priority defined in the DATAFLOW Designer model. Remarks: The behavior of an Active Part is user defined and can not be covered by generated test cases. See below on how to add user defined tests. |
History: Added in V1.0 |
Active Interrupt |
The unit test for an Active Interrupt contains the following test cases: test<name>IrqAP_<handler> Generated once per handler. Asserts that the Active Interrupt calls IsrEntry before the user defined interrupt handler is called and IsrExit after the user defined handler exists. Remarks: The behavior of an Active Interrupt is user defined and can not be covered by generated test cases. See below on how to add user defined tests. |
History: Added in V1.0 |
Protocol |
The unit test for a protocol contains the following test cases: test<Name>Protocol_maxSerializedSize Generated once per protocol. Asserts that the number of serialized bytes is equal to the MAX_SERIALIZED_SIZE_BYTES constant.
test<Name>Protocol_defaultConstructor Generated once per protocol. Asserts that the default (parameterless) constructor initializes all fields with the correct default value.
test<Name>Protocol_customConstructor Generated once per protocol. Asserts that the custom constructor initializes all fields with the given value.
test<Name>Protocol_copyConstructor Generated once per protocol. Asserts that the copy constructor initializes all fields with the value of the copied protocol.
test<Name>Protocol_assignmentOperator Generated once per protocol. Asserts that the assignment operator sets all fields to the value of the assigned protocol.
test<Name>Protocol_assignmentOperator_assignSelf Generated once per protocol. Asserts that the assignment operator supports self assignment.
test<Name>Protocol_compareOperators Generated once per protocol. Asserts that the compare operator compares the value of each field with the other protocol.
test<Name>Protocol_serialize_deserialize Generated once per protocol. Asserts that all fields values are the same after the protocol is serialized and de-serialized again.
test<Name>Protocol_field_<field> Generated once per protocol. Asserts that the field getter and setter methods allow to change and retrive the field value. |
History: Added in V1.0 |
Struct |
The unit test for a struct contains the following test cases: test<Name>Struct_maxSerializedSize Generated once per struct. Asserts that the number of serialized bytes is equal to the MAX_SERIALIZED_SIZE_BYTES constant.
test<Name>Struct_defaultConstructor Generated once per struct. Asserts that the default (parameterless) constructor initializes all fields with the correct default value.
test<Name>Struct_customConstructor Generated once per struct. Asserts that the custom constructor initializes all fields with the given value.
test<Name>Struct_copyConstructor Generated once per struct. Asserts that the copy constructor initializes all fields with the value of the copied struct of the same type.
test<Name>Protocol_assignmentOperator Generated once per struct. Asserts that the assignment operator sets all fields to the value of the assigned struct of the same type.
test<Name>Protocol_assignmentOperator_assignSelf Generated once per struct. Asserts that the assignment operator supports self assignment.
test<Name>Protocol_compareOperators Generated once per struct. Asserts that the compare operator compares the value of each field with the other struct of the same type.
test<Name>Protocol_serialize_deserialize Generated once per struct. Asserts that all fields values are the same after the struct is serialized and de-serialized again.
test<Name>Protocol_field_<field> Generated once per field. Asserts that the field getter and setter methods allow to change and retrive the field value. |
History: Added in V2.0 |
Custom Type |
The unit test for a protocol contains the following test cases: test<Name>Type_defaultConstructor Generated once per type. Asserts that the default (parameterless) constructor initializes the type instance with the correct default value.
test<Name>Type_customConstructor Generated once per type. Asserts that the custom constructor initializes the type instance with the given value.
test<Name>Type_copyConstructor Generated once per type. Asserts that the copy constructor initializes the type instance with the value of the copied instance of the same type.
test<Name>Type_assignmentOperator Generated once per type. Asserts that the assignment operator sets the instance to the value of the assigned instance of the same type.
test<Name>Type_assignmentOperator_assignSelf Generated once per type. Asserts that the assignment operator supports self assignment.
test<Name>Type_compareOperators Generated once per type. Asserts that the compare operator compares the value with the other instance of the same type.
test<Name>Type_orderOperators Generated once per type. Asserts that the order operators return the correct value when compared with an other instance of the same type.
test<Name>Type_reset Generated once per type. Asserts that the value is reset to the initial value.
test<Name>Type_setValue Generated once per type. Asserts that the value of the instance can be set to the given raw value.
test<Name>Type_serialize_deserialize Generated once per type. Asserts that the value is the same after the type is serialized and de-serialized again. |
History: Added in V2.0 |
Supported Test Frameworks
The tests can be generated for a given test framework per toolchain. If tests for different frameworks are required for the same project, a toolchain must be added per framework.
Supported Frameworks:
- MS Test
- Google Test (Future)
- cppUnit (Future)
Microsoft Testing Framework
The Microsoft testing framework is part of the Visual Studio IDE. It uses managed C++ classes as unit tests. Please refer to the Microsoft documentation for more details.
History: Added in V1.0
Unit Test Coding Style
The coding style configuration of the Build Configuration as described in the article Coding Style Configation will be applied to all generated unit test code.
Add User Defined Test Cases
The generated unit tests contain test cases for all features of the generated code known to the DATAFLOW Designer. This does not include behavior of Active Parts and Active Interrupts. Therefore it is required for the user to added additional test cases to test the behavior of these software items.
Required Module: DATAFLOW Code
This Article has been written based on V2.1.1 of the DATAFLOW software.
Latest update 2023-06-01 by WUE.
Comments
0 comments
Please sign in to leave a comment.