Refactored some parts of the testing infrastructure for easier reuse.