Remove more code duplication in tests