Refactored to bring common test tool methods into a module of its own.