Refactor the functional tests to remove code duplication.