Skip to content

Instantly share code, notes, and snippets.

@drumnkyle
Last active August 17, 2018 18:46
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save drumnkyle/28759b11628eac860e77fb1297cdc7e9 to your computer and use it in GitHub Desktop.
ButtonScrollPerformanceTest
#import <XCTest/XCTest.h>
#import <KIF/KIF.h>
#import "KSScrollPerformanceDetector.h"
#import "usage.h"
// This is specifically chosen to be the right speed to not trigger optimizations
static const CGFloat KSScrollPerformanceTestsVelocity = -0.15f;
@interface ButtonScrollPerformanceTests : KIFTestCase <KSScrollPerformanceDetectorDelegate>
@property(nonatomic, assign, readwrite) NSInteger droppedFramesLimit;
@property(nonatomic, assign, readwrite) NSInteger frameDropEventsLimit;
@property(nonatomic, strong, nonnull) KSScrollPerformanceDetector *scrollPerformanceDetector;
@property(nonatomic, strong, nonnull) UITableView *tableView;
@end
@implementation ButtonScrollPerformanceTests
- (void)beforeEach {
self.scrollPerformanceDetector = [[KSScrollPerformanceDetector alloc] init];
self.scrollPerformanceDetector.delegate = self;
self.droppedFramesLimit = 3;
self.frameDropEventsLimit = 3;
}
- (void)setUp {
[super setUp];
// Put setup code here. This method is called before the invocation of each test method in the class.
self.continueAfterFailure = YES;
}
- (void)testButtonPerformance {
[tester tapViewWithAccessibilityLabel:@"Button"];
[tester tapViewWithAccessibilityLabel:@"Performance"];
[self scrollTableToEndWithIdentifier:@"performance-test-table"];
}
- (void)scrollTableToEndWithIdentifier:(NSString *)accessibilityIdentifier {
UITableView *tableView;
[tester waitForAccessibilityElement:NULL view:&tableView withIdentifier:accessibilityIdentifier tappable:NO];
self.tableView = tableView;
NSIndexPath *lastIndexPath = [NSIndexPath indexPathForRow:[self.tableView numberOfRowsInSection:0] - 1 inSection:0];
NSArray<NSIndexPath *> *visibleIndexPaths = [self.tableView indexPathsForVisibleRows];
[self.scrollPerformanceDetector resume];
while (![visibleIndexPaths containsObject:lastIndexPath]) {
[tester scrollViewWithAccessibilityIdentifier:accessibilityIdentifier byFractionOfSizeHorizontal:0.0f vertical:KSScrollPerformanceTestsVelocity];
visibleIndexPaths = [self.tableView indexPathsForVisibleRows];
[self.scrollPerformanceDetector clearFrameDropCount];
}
[self.scrollPerformanceDetector pause];
}
- (void)framesDropped:(NSInteger)framesDroppedCount cumulativeFramesDropped:(NSInteger)cumulativeFramesDropped cumulativeFrameDropEvents:(NSInteger)cumulativeFrameDropEvents {
if (framesDroppedCount >= self.droppedFramesLimit) {
XCTFail(@"Past limit for number of dropped frames");
}
if (cumulativeFrameDropEvents >= self.frameDropEventsLimit) {
XCTFail(@"Past limit for number of frame drop events");
}
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment