Removing code duplicates in tests