Solutions for "mocking" out NSUserDefaults?
Solutions for "mocking" out NSUserDefaults?
- Subject: Solutions for "mocking" out NSUserDefaults?
- From: Jeremy Higgs <email@hidden>
- Date: Mon, 9 Jan 2006 23:21:25 +1100
Hi everyone,
In the code that I'm trying to unit test, there are some calls to
[NSUserDefaults standardUserDefaults] that I'm trying to manipulate
(returning certain values, etc). At first I tried to mock out
NSUserDefaults, but found out that didn't work because
standardUserDefaults is a class/static method. Ouch.
I then tried to create a class that would pose as NSUserDefaults
(through NSObject's poseAsClass: method), but didn't get that working
either (even after calling poseAsClass: in the tested class's +
(void)load method).
Does anyone have any suggestions for imitating or acting like
NSUserDefaults transparently in tests? My last resort is to write a
class that will wrap NSUserDefaults and allow me to mock it out and
return what I want, but it seems a bit hackish.
Any ideas?
Thanks!
Jeremy
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden