Remove code duplication in tests.