Xcode Scheme Default Location is ignored in Tests
Asked Answered
G

1

9

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?

Greaser answered 7/11, 2016 at 18:24 Comment(3)
Did you ever resolve this? I have pretty mush the same issue: #49437677Soar
Unfortunately notGreaser
Do the tests create a fresh, never-run-before build? One that must ask user permission before accessing location services? That lack of permission might be why the simulated location is not available.Cuman
Y
6

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.

Yardarm answered 26/3, 2019 at 4:18 Comment(1)
It's not working for me when I use fastlane or xcodebuild in the command line. It only works if I run cmd+U in Xcode. Any ideas?Turnstile

© 2022 - 2024 — McMap. All rights reserved.