Member-only story
It’s easy to see Unit Testing about Core Data operations like CRUD, which is short for Create, Read, Update and Delete, but it’s quite rare to see people Unit Testing to verify the correctness of entity and its properties.
In the following code:
XCTUnwrap
will try to unwrap a non-nil value, from a given parameter. In our case, we are trying to create anNSEntityDescription
instance.- With the instance of our entity, we could verify properties with the helper function.
- In the helper function, we use
attributesByName
andpropertiesByName
to retrieve the attribute and property of a given property name. AssertEqual
to see if the attribute and property are as expected.
Above all, the key part of this method is this tiny piece of code as the helper function, which could be added as the fundamental helper function for Core Data related testing.