Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode Scheme Default Location is ignored in Tests

I've created a GPX file and added it to my project. If I have my project running, I can select the GPX file from the dropdown of possible locations to simulate and have it correctly apply the defined path.

The project contains 2 schemes: the Main Scheme and the MainTest Scheme. I've set up both to use the GPX file as the "Default Location" on the "Options" tab. Further, Under the "Test" area of both schemes, I've specified the same file again.

Main Scheme Run Options Main Scheme Run Options

Main Scheme Test setup Main Scheme Test

Test Scheme Run Options Test Scheme Run Options

Test Scheme Test setup Test Scheme Test setup

When I Run the app on a simulator, it correctly applies the simulated location. However, when I run my tests, the simulated location is not applied. I'm at a loss to exaplain why the the tests are not automatically applying the location. Once the tests are compiled and installed on the simulator/test device, I can apply the desired simulated location with the dropdown in Xcode. However, in order to set up automated tests, the scheme needs to properly apply the target simulated location since there is no way to set the simulated lcoation from the test scripts. Is there something else I am missing?

like image 620
Jan K Avatar asked Nov 07 '16 18:11

Jan K


1 Answers

This one's a bit old, but since there were some relatively recent requests for the same thing, I've put together an example using Xcode 10. I have no idea if there were other issues back when this question was written, but here's how it works today.

For tests, you need to specify the GPX file to use in the scheme's Test settings. Here's an example from a test project I threw together:

Test simulated location settings

Also, make sure that the scheme is marked "share" so that the settings get checked in to your source repo and get checked out by other users or your CI pipeline.

In the test project I put together, I included a GPX file for the Space Needle, and one for the Statue of Liberty. My run settings don't specify a GPX file or location, my unit tests use/expect the Space Needle and my UI tests use/expect the Statue of Liberty. All worked as expected. You could, of course, use one GPX file for all three targets.

One thing to keep in mind is that location data takes a bit of time to come in, so you need to use appropriate waitForExpectations checks in order to give the location manager time to settle.

I've posted the full project that demonstrates GPX files working with both XCTests and XCUITests on GitHub.

like image 146
clarus Avatar answered Sep 28 '22 05:09

clarus