xcode 如何获取 iOS 框架测试目标并在虚拟应用程序中运行它?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/42423941/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to take iOS Framework testing target and run it in a dummy app?
提问by Adam Venturella
So I am running into an issue where my Framework needs access to the KeyChain
. That's fine, but it seems to fail when running in the simulator. Digging around it seems to be a known issue that xctest
does the wrong thing here. Fair enough, bugs happen. In the Apple Developer forums it's discussed here:
所以我遇到了一个问题,我的框架需要访问KeyChain
. 这很好,但是在模拟器中运行时似乎失败了。挖掘它似乎是一个已知的问题,xctest
在这里做错了事情。很公平,错误发生了。在 Apple Developer 论坛中,这里讨论了它:
Right.
This is a well-known issue with library tests (sometimes called logic tests by Xcode). Those tests are run by a tool (xctest) that does not have entitlements. Historically this caused problems for folks using custom entitlements (to access CloudKit, for example) but now it affects folks using the keychain as well.
AFAIK there's no direct workaround. However, I believe you can avoid the problem by running this test code within your app(emphasis mine) (in the docs this is called an app test).
Because these run inside your app, they get the app's entitlements. If you don't have an app handy, you can create a dummy one just to host the tests.(emphasis mine how do I do this?)
Please try this out and let us know if you hit any snags. Oh, and don't let the availability of a workaround prevent you from filing a bug about this. Xcode should be able to run library tests with entitlements, and this recent keychain change makes this even more important. Share and Enjoy
对。
这是库测试(有时被 Xcode 称为逻辑测试)的一个众所周知的问题。这些测试由没有权限的工具 (xctest) 运行。从历史上看,这会给使用自定义权利(例如访问 CloudKit)的人们带来问题,但现在它也会影响使用钥匙串的人们。
AFAIK 没有直接的解决方法。 但是,我相信您可以通过在您的应用程序中运行此测试代码来避免这个问题(重点是我的)(在文档中这称为应用程序测试)。
因为它们在您的应用程序中运行,所以它们获得了应用程序的权利。如果您手边没有应用程序,您可以创建一个虚拟应用程序来托管测试。(强调我的 我该怎么做?)
请尝试一下,如果您遇到任何障碍,请告诉我们。哦,不要让解决方法的可用性阻止您提交有关此的错误。Xcode 应该能够运行带有权利的库测试,而最近的钥匙串更改使这一点变得更加重要。分享和享受
https://forums.developer.apple.com/message/179846(see: Eskimo's reply on Nov 4, 2016 2:12 AM)
https://forums.developer.apple.com/message/179846(参见:爱斯基摩人于 2016 年 11 月 4 日凌晨 2:12 的回复)
He again goes on to say in another reply:
他在另一个回复中再次继续说:
- You can avoid the problem by running your tests within an app, creating a dummy app if you don't have one handy.(emphasis mine)
- Feel free to file your own bug about this limitation.
- 您可以通过在应用程序中运行测试来避免该问题,如果您手头没有,则创建一个虚拟应用程序。(强调我的)
- 请随意提交有关此限制的错误。
So again he references:
所以他再次引用:
You can avoid the problem by running your tests within an app, creating a dummy app if you don't have one handy.
您可以通过在应用程序中运行测试来避免该问题,如果您手头没有,则创建一个虚拟应用程序。
I'm more than happy to do this, I just can't seem to figure out how.
我很高兴这样做,我只是似乎无法弄清楚如何。
The parts I have:
我有的部分:
Framework Project
|
|- Unit Test Target
|- Framework Target
Dummy App Project
|
|- ??? How do I make this run the Framework's Unit Test Target?
回答by Adam Venturella
Ah, this article helped:
啊,这篇文章有帮助:
https://medium.com/@ryuichi/setup-host-app-for-keychain-tests-in-xcode-8-97222611917e#.z3zpqwnzt
https://medium.com/@ryuichi/setup-host-app-for-keychain-tests-in-xcode-8-97222611917e#.z3zpqwnzt
I was adding a totally new app project, I just needed to add a new Target in the Framework project for a Single View Application
我正在添加一个全新的应用程序项目,我只需要在 Framework 项目中添加一个新的 Target Single View Application
That then allows me to select Host Application
in the testing target.
然后允许我Host Application
在测试目标中进行选择。
Using my previous diagram, the final result that worked is:
使用我之前的图表,最终有效的结果是:
Framework Project
|
|- Unit Test Target
|- Framework Target
|- Dummy App Target