I want to unit test a UICollectionView which is inside a UIViewController (e.g. I want to test that the UICollectionView has the number of cells that I am expecting it to have in my unit test)
My unit test is based on the following blog (on how to unit test a view controller): http://yetanotherdevelopersblog.blogspot.co.il/2012/03/how-to-test-storyboard-ios-view.html
In the unit test I am able to get a pointer to the UICollectionView in the UIViewController which I am testing. Here is the code in my test's setUp method:
storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
viewController = [self.storyboard instantiateViewControllerWithIdentifier:@"MainViewController"];
[viewController performSelectorOnMainThread:@selector(loadView) withObject:nil waitUntilDone:YES];
self.collectionView = viewController.collectionView
Unfortunately, there are no cells in this UICollectionView (i.e. self.collectionView.visibleCells.count equals 0, hence I cannot access the cells and test that the data is what I am expecting it to be), although when debugging I can see that my application add those cells to the collection view.
What am I doing wrong? Any tips & tricks on how to unit test UICollectionView within a UIViewController?
Edit:
After Roshan's help I can now narrow down my problem. I am unit testing a UIViewController that has a UICollectionView. In my unit test I want to test that values of the cells inside CollectionView is what I am expecting it to be. But, collectionView:cellForItemAtIndexPath: is not being invoked on my ViewController and hence my cells doesn't exist when this is invoked as a unit test. Any idea?