Xcode方案默认位置在测试中被忽略 [英] Xcode Scheme Default Location is ignored in Tests

查看:79
本文介绍了Xcode方案默认位置在测试中被忽略的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了一个GPX文件并将其添加到我的项目中.如果我正在运行项目,则可以从可能的位置的下拉列表中选择GPX文件进行模拟,并使其正确应用定义的路径.

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.

该项目包含2个方案:Main Scheme和MainTest Scheme.我都设置为将GPX文件用作选项"选项卡上的默认位置".此外,在两个方案的测试"区域下,我再次指定了相同的文件.

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.

主要方案运行选项

主要方案测试设置

测试方案运行选项

测试方案测试设置

当我在模拟器上运行该应用程序时,它会正确应用模拟的位置. 但是,当我运行测试时,不会应用模拟的位置.我无所适从地解释了为什么测试没有自动应用该位置.一旦测试被编译并安装在模拟器/测试设备上,我就可以通过Xcode中的下拉菜单应用所需的模拟位置. 但是,为了设置自动化测试,该方案需要正确地应用目标模拟位置,因为无法从测试脚本中设置模拟标记.还有其他我想念的东西吗?

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?

推荐答案

这个有点老了,但是由于对同一事物有一些相对较新的请求,因此我整理了一个使用Xcode 10的示例.想知道在撰写此问题时是否还有其他问题,但这就是今天的工作方式.

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.

对于测试,您需要指定要在方案的测试"设置中使用的GPX文件.这是我一起整理的一个测试项目的示例:

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:

此外,请确保该方案标记为共享",以便将设置签入您的源存储库并被其他用户或您的CI管道签出.

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.

在我进行的测试项目中,我包括了一个用于太空针塔的GPX文件,一个用于自由女神像的文件.我的运行设置未指定GPX文件或位置,我的单元测试使用/预期了太空针,我的UI测试使用/预期了自由女神像.所有工作均按预期进行.当然,您可以对所有三个目标使用一个GPX文件.

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.

要记住的一件事是位置数据需要一点时间才能进入,因此您需要使用适当的waitForExpectations检查以使位置管理器有时间解决.

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.

我已经在GitHub上发布了完整的项目,该项目演示了同时使用XCTests和XCUITests的GPX文件.在GitHub

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

这篇关于Xcode方案默认位置在测试中被忽略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆