如何获取iOS Framework测试目标并在虚拟应用程序中运行它? [英] How to take iOS Framework testing target and run it in a dummy app?

查看:96
本文介绍了如何获取iOS Framework测试目标并在虚拟应用程序中运行它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我遇到了一个问题,我的框架需要访问 KeyChain 。这没关系,但在模拟器中运行时似乎失败了。挖掘它似乎是一个已知的问题, xctest 在这里做错了。很公平,错误发生了。在Apple Developer论坛中,我们在这里讨论:


正确。



这是一个众所周知的库测试问题(有时称为Xcode的逻辑测试)。这些测试由没有权利的工具(xctest)运行。从历史上看,这会给使用自定义权利的人造成问题(例如,访问CloudKit)但现在它也会影响使用钥匙串的人。



AFAIK没有直接的解决方法。 但是,我相信您可以通过在您的应用中运行此测试代码来避免此问题(强调我的)(在文档中称为app测试)。



因为这些在你的应用程序中运行,所以他们获得了应用程序的权利。
如果你没有方便的应用程序,你可以创建一个虚拟的,只是为了主持测试。(强调我的我该怎么做?



请尝试一下,如果遇到任何障碍,请告知我们。
哦,不要让变通方法的可用性阻止你提交有关此问题的错误。 Xcode应该能够使用权利运行库测试,而最近的钥匙串更改使这一点变得更加重要。
分享和享受



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:

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

https://forums.developer.apple.com/message/179846 (see: Eskimo's reply on Nov 4, 2016 2:12 AM)

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?

解决方案

Ah, this article helped:

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

That then allows me to select Host Application in the testing target.

Using my previous diagram, the final result that worked is:

Framework Project
    |
    |- Unit Test Target
    |- Framework Target
    |- Dummy App Target

这篇关于如何获取iOS Framework测试目标并在虚拟应用程序中运行它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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