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