Why does the following unit test pass using Xcode 5.0 and XCTesting? I mean, I understand the bottom line: 1 == 0 is not evaluated. But why is it not evaluated? How can I make this perform so that it would fail?
- (void)testAnimationResult
{
[UIView animateWithDuration:1.5 animations:^{
// Some animation
} completion:^(BOOL finished) {
XCTAssertTrue(1 == 0, @"Error: 1 does not equal 0, of course!");
}];
}
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With