I'm getting into Unit Testing for the first time, and trying to test a UITableView
that is in my UITableViewController
, but I'm getting failed tests.
This should have 1 subview for the 1 UITableView
but I get an error "View does not have a table subview".
- (void)testParentViewHasTableViewSubview
{
NSArray *subviews = self.vcToTest.view.subviews;
XCTAssertTrue([subviews containsObject:self.vcToTest.tableView], @"View does not have a table subview");
}
This should have exactly 6 rows because that information is hardcoded, but I think because my UITableView
is coming up as nil I get an error "Table has 0 rows but it should have 6".
- (void)testTableViewNumberOfRowsInSection
{
NSInteger expectedRows = 6;
XCTAssertTrue([self.vcToTest tableView:self.vcToTest.tableView numberOfRowsInSection:0]==expectedRows, @"Table has %ld rows but it should have %ld", (long)[self.vcToTest tableView:self.vcToTest.tableView numberOfRowsInSection:0], (long)expectedRows);
}
I don't know if it has to do with the UITableView
coming with the UITableViewController
instead of the UITableView
being added as an outlet to a UIViewController
, or what exactly. All of my other simple tests are working (conforms to table view data source, is connected to delegate, etc.).
Has anyone been through this before?
Here is my setUp
:
- (void)setUp {
[super setUp];
// Put setup code here. This method is called before the invocation of each test method in the class.
self.vcToTest = [[TableViewController alloc] init];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
self.vcToTest = [storyboard instantiateViewControllerWithIdentifier:@"testTableView"];
[self.vcToTest performSelectorOnMainThread:@selector(loadView) withObject:nil waitUntilDone:YES];
}
Aucun commentaire:
Enregistrer un commentaire