Stubbing Different Library Functions on Test Case by Test Case Basis

Question:
Is it possible to have different library functions stubbed out/not stubbed on a test case by test case basis without rebuilding the environment?
Answer:

The library stubs feature is for _all_ the library functions that you might want "stubbed" in test cases in your environment. If the library functions are reference in your unit under test, then by default it will be stubbed in all test cases for functions in that unit.
 

If you would like a library function to be stubbed on a test case by test case basis, what you can do is use User Globals user code to create a global variable for each stub to control whether the real function is called or whether the stub code is used.  
 




 
Here is an example of the User Global variables that you can create:
 

VCAST_USER_GLOBALS_EXTERN int VCAST_STUB_LIBFUNC1;
VCAST_USER_GLOBALS_EXTERN int VCAST_STUB_LIBFUNC2;


Then, in configure stubs user code (Environment | Configure Stubs)




for each stubbed library (beginning of stub), you would enter something like the following:


extern prototype for libfunc1(...);

if ( VCAST_STUB_LIBFUNC1 == 0 )
return libfunc1(...);

 



Article ID: 1504
Last updated: 2019-12-04
Revision: 4
VectorCAST -> C++ Unit Testing -> Stubbing Different Library Functions on Test Case by Test Case Basis
https://kb.vector.com/entry/1504/