How can I parameterize my test scenarios?
Cpp sample model: Samples/CppSamples/TestConductor/TestingCookbook/CppParams
C sample model: Samples/CSamples/TestConductor/TestingCookbook/CParams
These samples demonstrate the TestConductor support for parameterization of test scenarios. With the techniques shown in the samples, the same test scenario can be reused for different inputs and outputs avoiding redundant specifications.
Using attributes (from the test architecture) to parameterize test scenarios
In the test package TPkg_Calculator several test scenarios can be found in which attributes are used in the test specification. These attributes are located in the test context. The used operations contain arguments and return values of different types (int, double, struct) as well as arguments with different directions (in,out,inout).
- to specify return value checks or out argument value checks
- to specify in argument values
- to assign return values or out argument values to attributes using post call test actions
- to specify in argument values checks
- to specify return values or out argument values of an operation to be stubbed
Of course attributes can also be used in general test actions.
Using an array to specify test data
The test package TPkg_Calculator_usingArray contains test scenarios for which the test data is specified in an array. For example in test case 'SD_tc_0_outarg_int' the message argument values are specified using values specified in the array arx. The first two values of each triple are used as input and the third value as corresponding output. The test sequence which should be run multiple times with different input/output combinations is located in a loop operator.
Using a CSV file to specify test data
If for some reasons the test data should not be specified in the test architecture, it is also possible to read the data from a file. But note that reading from a file might not be available on a target. The test package TPkg_Calculator_usingCSV contains a test scenario in which the message argument values are specified using values specified in a CSV file. Again the test sequence which should be run multiple times with different input/output combinations is located in a loop operator. The reference implementation for reading data from a CSV file can be found in class CSVDataReader in package DataStore. This is a general implementation which can be reused in other models.