I'm using Xcode's OCUnit to write unit tests, and my tests call a method that performs an animation. I want the test method to continue only after the an开发者_运维问答imation is completed.
The method that performs the animation doesn't have an animation delegate, and i don't think that it should have.
How can i wait for the animation to end in the test method, without setting an animation delegate?
You don't want to actually wait for the animation; that would take the time the animation takes to run. If you have a few thousand tests, this can add up.
More effective is to mock 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+SpecFlywheel.h"
@implementation UIView (SpecFlywheel)
#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.
精彩评论