I would like to test the deserialization of my object basket of type Basket
which contains an array of objects of typeAProduct
.
All of my product classes inherit from AProduct
which is an abstract class.
Gradually, I will have more and more product classes with, for each, different attributes.
Currently, that is how I test the deserialization of my Basket:
Basket *oldBasket = BasketInstance;
[BasketInstance resetBasket]; // BasketInstance is a macro which points on the current Basket in singleton.
[BasketInstance deserializeItself:[self getBasketSerializedForTest]]; // getBasketSerializedForTest return a dictionnary of the same basket serialized.
XCTAssertTrue([BasketInstance isEqual:oldBasket], @"Basket deserialization is no correct");
The main problem with this implementation is that I have to override the isEqual
method in Basket
class and for each AProduct
object, override isEqual
method to check all of the attributes. I think this is very dangerous because if me or an other developer adds a new attribute and forgets to check the values of this attribute on the isEqual
method, the unit test of the basket could succeed with a broken deserilization.
Is there any solution to avoid this risk ? I though parse all of the properties of the class and for each attribute, run isEqual
method, but I wish there is a much better solution.
Thanks