Compound Test Cases: Initialization Code and Complex Preconditions
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:
- 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.)
- 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.