【发布时间】:2014-06-24 12:10:39
【问题描述】:
这是我的 h 文件
@class TBL_CardView;
@interface TBL_CardsOnTableView: NSObject
- (CGPoint) addCard:(TBL_CardView *)cardView didFailWithError:(NSError **)error;
- (unsigned int) numberOfCardOnTable;
- (NSArray*) cardsOnTableWithPosition;
@end
@interface TBL_CardOnTableWithPosition: NSObject
- (instancetype)initWithCardView:(TBL_CardView*) cardView withPosition:(NSUInteger) position;
@property(readonly) TBL_CardView* card;
@property(readonly) NSUInteger position;
@end
在我做的m文件中
- (NSArray*) cardsOnTableWithPosition
{
return (NSArray*) _cardsOnTable;
}
_cardsOnTable 是
NSMutableArray *_cardsOnTable;
_cardsOnTable = [[NSMutableArray alloc] initWithCapacity:8];
然后我用这段代码添加新对象:
TBL_CardOnTableWithPosition* cvwp = [[TBL_CardOnTableWithPosition alloc] initWithCardView:cardView withPosition:avalableLocation] ;
[_cardsOnTable addObject:cvwp];
这就是我在单元测试中的测试方式
[table cardsOnTableWithPosition];
TBL_CardOnTableWithPosition* cvwp1 = [[TBL_CardOnTableWithPosition alloc] initWithCardView:cardView1 withPosition:1] ;
NSLog(@"%@", [table cardsOnTableWithPosition]);
NSArray* array = [table cardsOnTableWithPosition];
NSArray * a = [[NSArray alloc] initWithArray:@[cvwp1]];
NSArray * d = [table cardsOnTableWithPosition];
XCTAssertEqual(a, d); // FAILD, but this I am expecting to failed
XCTAssertEqualObjects(a, d); // FAILD
XCTAssertEqualObjects(@[cvwp1], [table cardsOnTableWithPosition]); // FAILD
XCTAssertTrue([a isEqualToArray:d]); // FAILD
在调试器中对象 a 和 d 是相同的,但我可以找到如何在单元测试中对其进行测试的方法。
知道为什么吗?
【问题讨论】:
标签: ios unit-testing nsarray xctest