0
我是新编写的单元测试代码。任何人都可以告诉我如何编写自定义collectionView单元格的单元测试代码。这是我试过的代码,它显示单元格是零。如何在xcode8中编写自定义collectionView单元的单元测试代码
#import <XCTest/XCTest.h>
#import "CollectionViewCell.h"
@interface CollectionViewCellTests : XCTestCase
{
UICollectionView *testCollectionView;
CollectionViewCell *customCell;
}
@end
@implementation CollectionViewCellTests
- (void)setUp {
[super setUp];
// Put setup code here. This method is called before the invocation of each test method in the class.
//[testCollectionView registerNib:[UINib nibWithNibName:@"CollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"Cell"];
// [testCollectionView registerClass:[CollectionViewCell class] forCellWithReuseIdentifier:@"Cell"];
}
- (void)tearDown {
// Put teardown code here. This method is called after the invocation of each test method in the class.
[super tearDown];
}
- (void)testCustomCollectionViewCell {
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
customCell = (CollectionViewCell *)[testCollectionView dequeueReusableCellWithReuseIdentifier:@"Cell" forIndexPath:indexPath];
XCTAssertNotNil(customCell, @"No Custom Cell Available");
}
但单元格显示为零 –
确保您已将您的tableview设置为有一些数据,这需要在您的设置部分完成。所以你必须公开你的类数据容器,以便你可以从你的uitest中添加一些数据。你可以在你的tableView中设置断点:numberOfRowsInSection正在被调用,你返回一个正确的金额,通常是你的Data.count – Wayne
我实际上建议你在XCUITests上观看一些简短的视频,你可以快速记录一些用户操作,并从那里完善你的测试。 – Wayne