Welcome to the new Parasoft forums! We hope you will enjoy the site and try out some of the new features, like sharing an idea you may have for one of our products or following a category.

Stubbing functions which are not declared in header file

anup_bd
anup_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.

Answers

  • [Deleted User]
    [Deleted User] Posts: 0 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 https://docs.parasoft.com/display/CPPDESKE1041/Using+Factory+Functions 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:
    https://parasoft.force.com/customerportal/MyCases