Refactor tests to remove some duplication.