Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using an URL scheme in XCTestCase

I want to run a test which awaits the response of a browser.

A test target has an Info.plist where I can register custom URL schemes. But those are never called. I know that an test target is not a real application.

Is there a way?

EDIT (for bounty): I want to write an integration test for a class that calls openUrl("tel://" + some phone number). How do I subscribe to this URL scheme in an XCTestCase?

like image 548
McZonk Avatar asked Oct 06 '14 20:10

McZonk


1 Answers

The question was retagged to OS X so my answer is no longer valid

Original answer

This is impossible. The basic reason is that the tests are connected to one running application instance, they have no control over the device, they are running as part of the application. You can probably open the URL but you won't be able to return to the application and do an assert.

Also note that XCUnit is a unit testing framework. You won't be able to write advanced integration test in it. You might be more successful with UI Automation but this specific test case will be very complicated even for it. For example, to open a link by your app in the simulator, you can create a HTML page that will redirect to the link and then use shell to exec open testLink.html -a "iOS Simulator". However, in my humble opinion this kind of tests is unreliable and realy hard to write and debug.

My advice would be to:

  1. Write an unit test that mocks [UIApplication openURL:] and verify that you are passing a correct URL to it. Or if you want the other direction, write a unit test that will call UIApplicationDelegate methods in the called order, simulating opening a link by your app. This is as far you can go with XCUnit.
  2. Test the rest manually.
like image 177
Sulthan Avatar answered Sep 18 '22 16:09

Sulthan