• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Solutions for "mocking" out NSUserDefaults?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: Solutions for "mocking" out NSUserDefaults?
      • From: Corbin Dunn <email@hidden>
  • Prev by Date: Problems using (verifying) mock objects more than once
  • Next by Date: Re: Crashing problem on Mac OS X 10.2
  • Previous by thread: Problems using (verifying) mock objects more than once
  • Next by thread: Re: Solutions for "mocking" out NSUserDefaults?
  • Index(es):
    • Date
    • Thread