Extracted some duplicated testing functionality