Yannick
Yannick

Reputation: 1106

Xcode : One test target for multiple app targets

I am wondering if you can link one Unit Testing bundle to multiple targets. So one can test all the application targets with one Testing bundle.

I have some shared code between all app targets but also some specific calculations based upon which app target is running.

Currently I have to set the Bundle Loader option in the Build Settings to the used application target's .app file if I want to test a different application target.

My question to you all is : can this be done without creating multiple test bundle targets for every app target, and without always changing the Bundle Loader option?

Upvotes: 41

Views: 6643

Answers (3)

Igor Vasilev
Igor Vasilev

Reputation: 351

You can create several test targets - one for each app target, and then simply put all of your actual test source files into a separated group folder, making sure you select all the test targets for each of the files. Described here: https://medium.com/@rijalab/how-to-use-one-test-target-files-for-two-app-targets-in-ios-37df53265a5

Upvotes: 0

Garba
Garba

Reputation: 146

You need to:

  • Select the target you want to test
  • Go to Test navigation tab
  • Right-click on test target you want to enable
  • Click on Enable [name_of_your_target]

enter image description here

Upvotes: 8

David Ansermot
David Ansermot

Reputation: 6112

No, at this point you can't. It's like the extensions, you have to create a new one for each project's targets you have.

It's not pretty usefull but if the code differes from one to another target, the tests can fail because of missing code, not failing code.
It's why it's not allowed.

Sorry for the negative answer.

Upvotes: 3

Related Questions