Stubbing functions which are not declared in header file

anup_bdanup_bd Posts: 2

Is there any way to stub a class member function which has been defined in CPP files completely. The code is very old and we cannot modify the structure of code for the sake of unit testing.


  • brian_nucklesbrian_nuckles Posts: 32 admin

    Hi Anupam,

    Is the member function only used within the source file it was defined? Stubs are generated from invocations of functions when their definitions are not included in the testing scope. If the function is used in a file other than which it was defined, generating stubs from only that file with the definition excluded should generate a stub.

    Otherwise, you may want to look into creating a factory function similar to the original member definition which performs the same function and is able to be used in test cases as a substitute.

    I would be interested to know why the legacy code needs to be stubbed but is also not able to be modified. It is possible that proper unit test setup may be enough to cover your use cases. If you are able to share the source code in question, we can investigate further through a support case at:

Sign In or Register to comment.