Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to take iOS Framework testing target and run it in a dummy app?

Tags:

xcode

ios

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?
like image 713
AJ Venturella Avatar asked Feb 23 '17 18:02

AJ Venturella


People also ask

How can I make my own iOS app framework?

Create your iOS Framework Framework under Framework & Library section. Give a name to your framework (select Include Unit Tests — optional), click Next and you should set your workspace as you add to and group options. Then click Create. Framework's creation.


1 Answers

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

enter image description here

like image 188
AJ Venturella Avatar answered Oct 05 '22 17:10

AJ Venturella