Best practice for unit tests that rely on internet access?

Toby Wintermute tjc at
Fri Apr 29 02:15:58 BST 2011

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..

Should one
a) Prompt the user for whether to skip the tests? (I hate this
option.. I dislike interactivity in installers)
b) Only run the tests if specifically set by AUTHOR_TEST or something,
otherwise mock the server? (I dislike this.. means few good tests run
for users)
c) Try to test if there's a working connection, and silently skip the
tests if not? (Risks skipping tests if the connect fails for other
reasons than no outbound HTTP allowed)
d) ???


Turning and turning in the widening gyre
The falcon cannot hear the falconer
Things fall apart; the center cannot hold
Mere anarchy is loosed upon the world

More information about the mailing list