ios - Compare two objects in objective-c unit test assert -



ios - Compare two objects in objective-c unit test assert -

i new in testing in objective-c have experience in .net mstest.

what best way compare 2 objects in objective c using xctassert?

example code below:

- (void)testnumericvalue_saveandload_shouldsaveandthenloadidenticalobject { [_numericvalue_1 savetodatabasewithkey:valid_key_1]; numericvalue *tmpnumericvalue = [[numericvalue alloc] loadfromdatabasewithkey:valid_key_1]; xctassertequalobjects(tmpnumericvalue, _numericvalue_1); } - (void)testloop_saveandload_shouldsaveandthenloadidenticalobject { [_loop_1 savetodatabase]; loop *tmploop = [[loop alloc] loadfromdatabase]; xctassertequalobjects(tmploop, _loop_1); }

i have many tests this. sure save , load functions work in proper way. of tests passing, failing. reason? want objects have same properties values. have compare of properties 1 one? there "cleaner" way?

thank time

some of them passing, failing. reason?

this because using default equality comparison.

i want objects have same properties values. have compare of properties 1 one? there "cleaner" way?

yes. override isequals compare properties one-by-one, , xctassertequalobjects comparisons correctly:

-(bool)isequal:(id)other { ... }

don't forget override hash well:

-(nsinteger)hash { ... }

here link answer discusses best practices overriding isequal: , hash.

ios objective-c unit-testing

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -