ios - How to XCTAssertEqual NSArray with custom objects? -
this h file
@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 in m file do
- (nsarray*) cardsontablewithposition { homecoming (nsarray*) _cardsontable; } _cardsontable
nsmutablearray *_cardsontable; _cardsontable = [[nsmutablearray alloc] initwithcapacity:8]; and add together new object code:
tbl_cardontablewithposition* cvwp = [[tbl_cardontablewithposition alloc] initwithcardview:cardview withposition:avalablelocation] ; [_cardsontable addobject:cvwp]; and how test in unit test
[table cardsontablewithposition]; tbl_cardontablewithposition* cvwp1 = [[tbl_cardontablewithposition alloc] initwithcardview:cardview1 withposition:1] ; nslog(@"%@", [table cardsontablewithposition]); nsarray* array = [table cardsontablewithposition]; nsarray * = [[nsarray alloc] initwitharray:@[cvwp1]]; nsarray * d = [table cardsontablewithposition]; xctassertequal(a, d); // faild, expecting failed xctassertequalobjects(a, d); // faild xctassertequalobjects(@[cvwp1], [table cardsontablewithposition]); // faild xctasserttrue([a isequaltoarray:d]); // faild in debuger objects , d same, can find way how test in unit test. thought why ?
i have found problem.
i needed implement - (bool)isequal:(id)object in custom objects.
ios unit-testing nsarray xctest
No comments:
Post a Comment