Creating Variables within Test Cases

Question:

Is there a way to create a variable within a testcase to determine the number of times that a particular stub was called?

Answer:
Yes, you can add a variable to the VectorCAST User Globals by selecting Environment | User Code | Edit.  

 

Any variables added in this location will be displayed in the parameter tree and are also accessible within Configure Stubs User Code. Take a look at the following image for more details.
 

 
Note:
  • These variables will only be displayed in the parameter tree after the environment has been rebuilt.



    To count the number of times a stub has been called you can add the User Global, initialize it to zero in the parameter tree, then add Configure Stubs User Code to increment the variable (Environment | Configure Stubs | Edit).



     
  • You will need to Save and Link after making modifications to Configure Stubs User Code.
  • If you have set your unit under test as a Stub-By-Function (SBF) unit, you will get an error indicating that the variable is undeclared. To get around this error, you will need to declare the variable as an extern in Unit Prefix User Code (Environment | User Code | Edit).



Article ID: 1515
Last updated: 2019-11-14
Revision: 6
VectorCAST -> C++ Unit Testing -> Creating Variables within Test Cases
https://kb.vector.com/entry/1515/