How to use Parasoft Dynamic stubs #5

wsuberswsubers Posts: 6

Hello Community,

I am a first time user of Parasoft's dynamic stubs. I am evaluating this feature as an alternate to using Google mock.

Can stubs be created for functions in the same class (C++) or same the same file(C)?

Comments

  • piotrpiotr Posts: 8

    Yes, C++test can create stubs for functions from the same file / class.
    In general, stub can be created if the function is used / called somewhere in the tested code (with some exceptions).

    C:

    void zoo(); // can be stubbed - used in goo()
    
    void foo() // cannot be stubbed - never called
    {
    }
    
    void goo() // can be stubbed - used in bar()
    {
      zoo(); // stubZoo() will be used here
    }
    
    void bar() // cannot be stubbed - never called
    {
      goo(); // stubGoo() will be used here (if exists)
    }
    

    C++:

    // .h
    class Stubs {
    public:
      void zoo(); // can be stubbed - used in Stubs::goo()
      void foo(); // cannot be stubbed - never called
      void goo(); // can be stubbed - used in Stubs::bar()
      void bar(); // cannot be stubbed - never called
    };
    
    // .cpp
    void Stubs::foo() // cannot be stubbed - never called
    {
    }
    
    void Stubs::goo() // can be stubbed - used in Stubs::bar()
    {
      this->zoo(); // stubZoo() will be used here
    }
    
    void Stubs::bar() // cannot be stubbed - never called
    {
      this->goo(); // stubGoo() will be used here (if exists)
    }
    
Sign In or Register to comment.