in reply to Re^2: How to use a private version of a published module?
in thread How to use a private version of a published module?

My test code does not call Rest::Client, which is what I need to mock. Rest::Client is used by the module under test, not the test code.

It does not matter where in the chain of calls REST::Client is used. It is the subs within REST::Client which are mocked. You do not need to change your module at all. Your test script sets up the mocking, instantiates an object of your class and when your test script calls some method of your class which, somewhere down the line, calls a method on REST::Client, that is what is magically mocked by Test::MockModule.

Trust me on this, mocking is definitely the way to go here. You don't have to use Test::MockModule - there are plenty of other good mocking modules. The very fact that there are many of them should hopefully indicate to you how prevalent mocking is as a valid test tool and to get around precisely the problem you are presently having.


🦛

  • Comment on Re^3: How to use a private version of a published module?

Replies are listed 'Best First'.
Re^4: How to use a private version of a published module?
by MARKWIN (Novice) on Jun 19, 2021 at 19:22 UTC
    The solution that worked, that used the module I had already written was
    use Package::Alias 'REST::Client'=>'Finance::IG::REST::Client' ;
    And a rename of my mock REST::Client into my own namespace. I could have called it MockREST::Client or anything really. So now there is no REST::Client in my heirachy, only Finance::IG::REST::Client which is in my namespace, but calling this before the module under test is used, means the module under test uses the mocked version not the real thing.

    This means there is no name space permission problem when I upload to CPAN.

    Thanks very much for everyones help.