Skip to content

Instantly share code, notes, and snippets.

@wearhere
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wearhere/76f6d26015325ecc9e5b to your computer and use it in GitHub Desktop.
Save wearhere/76f6d26015325ecc9e5b to your computer and use it in GitHub Desktop.
Examining table view cells using Subliminal.
#import <Subliminal/Subliminal.h>
@interface TableViewCellTest : SLTest
@end
@implementation TableViewCellTest
- (void)setUpTest {
[super setUpTest];
// navigate to the table view
}
- (void)testTableLayout {
SLAssertTrue(SLAskApp(numberOfRows) == 1, @"There should be only one row.");
SLAssertTrue([SLAskApp1(labelOfRowAtIndex:, @1) isEqualToString:@"Foo"], @"The first and only cell should say 'Foo'.");
}
@end
#if INTEGRATION_TESTING
#import <Subliminal/Subliminal.h>
#endif
@interface TableViewController : UITableViewController
@end
@implementation TableViewController
- (instancetype)initWithNibName:(NSString *)nibName bundle:(NSBundle *)bundle {
self = [super initWithNibName:nibName bundle:bundle];
if (self) {
#if INTEGRATION_TESTING
[[SLTestController sharedTestController] registerTarget:self forAction:@selector(numberOfRows)];
[[SLTestController sharedTestController] registerTarget:self forAction:@selector(labelOfRowAtIndex:)];
#endif
}
return self;
}
- (void)dealloc {
#if INTEGRATION_TESTING
[[SLTestController sharedTestController] deregisterTarget:self];
#endif
}
- (NSNumber *)numberOfRows {
// assumes that there's only one section
return @([self tableView:self.tableView numberOfRowsInSection:0]);
}
- (NSString *)labelOfRowAtIndex:(NSNumber *)index {
NSIndexPath *rowPath = [NSIndexPath indexPathForRow:[index unsignedIntegerValue] inSection:0];
UITableViewCell *cellAtRow = [self tableView:self.tableView cellForRowAtIndexPath:rowPath];
return cellAtRow.textLabel.text;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment