|Just another Perl shrine
Testing with Test::Mock::HTTP::Tinyby Bod (Parson)
|on Sep 26, 2023 at 20:11 UTC
Bod has asked for the wisdom of the Perl Monks concerning the following question:
I am writing some tests of a module that fetches a webpage using HTTP::Tiny->get
To test it, I am trying to use Test::Mock::HTTP::Tiny but I've never tried to use a Test::Mock module before. It's been on my radar since kcott mentioned their existence many moons ago. Now I have the need for one...but the documentation is lacking (to put it mildly!)
First I've run this code to get the mock data:
Then I've renamed all the references to the domain www.way-finder.uk (a real domain) to www.testing.crawl (a mock domain). I've done this because I don't want the tests going out to a live site as it will change over time invalidating the tests.
My test file looks like this:
The method $crawl->crawl uses HTTP::Tiny->get to get the web address.
Is this the right way to use Test::Mock objects or am I completely off track here?