Submit and vote on feature ideas.

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.

How to use Parasoft Dynamic stubs #5

Options
wsubers
wsubers Posts: 7

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

  • piotr
    piotr Posts: 36
    Options

    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)
    }