Refactor tests to avoid duplication