Factor out duplicated code in a test.