Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unit testing methods with I/O in iOS

What are the best approaches to unit test methods that include I/O operations in iOS?

For example, I'm considering using Objective-C categories to redefine the behavior of I/O methods such as imageNamed. However, this prevents black-box unit testing because it's necessary to know which I/O methods are used in the implementation.

like image 577
hpique Avatar asked Jul 14 '26 01:07

hpique


1 Answers

Either pass in the results of the I/O operation so that test data can be supplied in place of the actual I/O data or use OCMock. I have used OCMock for exactly this purpose. If you are considering OCMock, do read at least the header file for all the methods available.

If working with Legacy code consider reading/studying the book Working Effectively with Legacy Code by Michael Feathers

like image 137
zaph Avatar answered Jul 15 '26 15:07

zaph



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!