Compound Test Cases: Initialization Code and Complex Preconditions

Question:
How do I call initialization code or set up complex preconditions for a compound test case?
Answer:
Compound test cases are often used to test scenarios that require non-trivial initialization. For example, a test that exercises a state machine may require one or more function calls to initialize the state machine and any associated data. VectorCAST provides several mechanisms for initializing data at the beginning of a compound test. 


The most straightforward way to add an initialization stage to a compound test is by creating an Initialization (INIT) Test and adding this as the first slot in your compound test. An initialization test does not call any testable function, but can access any global data within the test harness. You can also add user code to the initialization test to insert custom C or C++ code into the test harness. Because a compound test case runs in one execution of the test harness, any setup done in the initialization test case will be seen by test cases in subsequent slots. 
 
Within the initialization test you may set up data that will be used by the rest of the compound test by: 
 
  1. Just as with regular test cases, you can use the test case parameter tree to set up any global data, class instances, etc. that are visible to the test harness. (Note: If you cannot see a particular global member ensure that your environment has the "whitebox" setting turned on.)


     
  2. To add arbitrary C or C++ initialization code to the test harness, open the initialization test case and select the Testcase User Code tab at the bottom of the test case screen. Enable Input or Expected user code and add your code. Make sure to hit the test compile button to ensure that the user code compiles.  


The second method is particularly useful if you already have code in your application that does the proper initialization. In many cases you can simply copy and paste the correct code.
 


Article ID: 1467
Last updated: 2019-10-29
Revision: 5
VectorCAST -> C++ Unit Testing -> Compound Test Cases: Initialization Code and Complex Preconditions
https://kb.vector.com/entry/1467/