Move common code into setUp function to reduce duplication.