Best practice for unit tests that rely on internet access?

Paul Johnson paul at
Fri Apr 29 10:28:27 BST 2011

On Fri, Apr 29, 2011 at 11:15:58AM +1000, Toby Wintermute wrote:
> What is the best practice for writing unit tests that rely on internet access?
> ie. You have a CPAN module which is all about talking to a web
> service.. So you have unit tests that do just that.
> What if the system testing it doesn't allow HTTP connections out? The
> tests will fail..

You're running into the limitation (if you want to see it as that) that
modules only really have one type of test.  This isn't usually a
problem, but in the case you mention it is.

I agree that unit tests should mock the service.  However, system tests
(or whatever you happen to call them) should test the actual service.

My suggestion would be to run mocked tests by default and provide a
method to run live tests should the user want to do that.  The user
should also have system tests for their whole application that will test
the live service too.

Paul Johnson - paul at

More information about the mailing list