This will, technically, work. But of course the test will sit and run for 2 seconds. If you have a few thousand tests, this can add up.
More effective is to stub out the UIView static method in a category so that it takes effect immediately. Then include that file in your test target (but not your app target) so that the category is compiled into your tests only. We use:
#import "UIView+Spec.h"
@implementation UIView (Spec)
#pragma mark - Animation
+ (void)animateWithDuration:(NSTimeInterval)duration animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion {
if (animations) {
animations();
}
if (completion) {
completion(YES);
}
}
@end
The above simply executes the animation block immediately, and the completion block immediately if it's provided as well.