1

I'm unit testing an iOS static library: so no UI, no app.

One of the unit tests requires to access to the address book and retrieve the list of contacts. The problem is that as I'm not launching any app on the simulator, the popup that should ask user for grant permissions to the address book never appears. So that, 'ABAddressBookRequestAccessWithCompletion' always return NO.

I found this similar topic: Grant access to NAB programatically on iOS 7.0 Simulator but does not apply to my case, as I'm not launching any app, just testing library methods.

Is there any way to access the address book's contacts while unit testing an static library?

Thanks!

quifago
  • 11
  • 1

2 Answers2

2

Unit testing assumes that you testing ONE unit at a time by mocking environment with test data and testing expected results. So in your case you need to mock response from addressbook instead of trying to get data from real addressbook.

Andrei Shender
  • 2,487
  • 22
  • 15
  • I'm testing ONE unit at a time: get contacts list. I already mocked contacts for testing other functions (sort,filter,...). But in this particular case, I wanted to test the get contacts feature. Thanks for your answer anyway – quifago Sep 12 '14 at 11:50
0

I came across same issue and read all the threads about granting access rights by modifying database in Simulator. And suddenly I've resolved it by other mean:

  • started Test not in Debug, but in Run mode (running it from JetBrains AppCode).

This shown me normal dialog on the simulator "grant access", and when I gave it, seems like everything works now as expected, including running from Debugger

Nick Entin
  • 1,087
  • 8
  • 18