Unit Test Configuration (DATAFLOW Code)

by Marco Wuelser

 

The DATAFLOW Code Generator can generate unit tests for the generated C++ code artifacts.

See the C++ Code Generation article for an overview.

Generated Unit Tests

The code generator can generate unit test for the following artifacts:

  • Active Container
  • Active Part
  • Active Interrupt
  • Protocol
  • Custom Type
  • Struct

 

Active Container

The unit test for an Active Container contains the following test cases:

test<Name>APC_IsInitialized

Generated once per active container.
Category: 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.
Category: 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.
Category: 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.
Category: 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.
Category: 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.
Category: Active Interrupt

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.
Category: 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.
Category: Protocol

Asserts that the default (parameterless) constructor initializes all fields with the correct default value.

 

test<Name>Protocol_customConstructor

Generated once per protocol.
Category: Protocol

Asserts that the custom constructor initializes all fields with the given value.

 

test<Name>Protocol_copyConstructor

Generated once per protocol.
Category: Protocol

Asserts that the copy constructor initializes all fields with the value of the copied protocol.

 

test<Name>Protocol_assignmentOperator

Generated once per protocol.
Category: 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.
Category: Protocol

Asserts that the assignment operator supports self assignment.

 

test<Name>Protocol_compareOperators

Generated once per protocol.
Category: 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.
Category: 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.
Category: 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.
Category: 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.
Category: Struct

Asserts that the default (parameterless) constructor initializes all fields with the correct default value.

 

test<Name>Struct_customConstructor

Generated once per struct.
Category: Struct

Asserts that the custom constructor initializes all fields with the given value.

 

test<Name>Struct_copyConstructor

Generated once per struct.
Category: 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.
Category: 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.
Category: Struct

Asserts that the assignment operator supports self assignment.

 

test<Name>Protocol_compareOperators

Generated once per struct.
Category: 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.
Category: 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.
Category: Struct

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.
Category: Custom Type

Asserts that the default (parameterless) constructor initializes the type instance with the correct default value.

 

test<Name>Type_customConstructor

Generated once per type.
Category: Custom Type

Asserts that the custom constructor initializes the type instance with the given value.

 

test<Name>Type_copyConstructor

Generated once per type.
Category: Custom 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.
Category: Custom 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.
Category: Custom Type

Asserts that the assignment operator supports self assignment.

 

test<Name>Type_compareOperators

Generated once per type.
Category: Custom 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.
Category: Custom 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.
Category: Custom Type

Asserts that the value is reset to the initial value.

 

test<Name>Type_setValue

Generated once per type.
Category: Custom 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.
Category: Custom 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

 

Configuration

The unit test generation can be configured in the Build Configuration on the Unit Test Page.

mceclip4.png

There are 3 groups of values that will be used to configure the generated unit tests:

  • Test Code
  • Test Paths
  • Test Case Categories

Test Code Group

mceclip1.png

In this group, the target test framework must be selected. For V2.0 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

mceclip2.png

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

mceclip3.png

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.

 

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.

 

This Article has been written based on V2.0.1 of the DATAFLOW Designer software. 
Latest update 2022-04-09 by WUE.

Required Module: DATAFLOW Code, DATAFLOW Frames

Go back