Link framework against App and Test Target

2k views Asked by At

I have a custom Framework I use within my normal App target as well as the corresponding UnitTest target. Turns out that confuses the runtime in such way that it is unable to choose the correct implementation since it has multiple choices:

objc[35580]: Class AClass is implemented in both ../MyApp.app/MyApp and ../MyApp.app/MyAppTests. One of the two will be used. Which one is undefined.

That of course leads to weird behavior if you try to check an object's class hierarchy or do any other class related checks.

So it boils down to the following two questions:

  1. I don't see similar logs for e.g. UIKit components, but this framework is also linked to both targets. Have I incorrectly compiled the framework?
  2. Is it just a trivial configuration issue I missed?

PS: I already checked similar posts like 1 or 2, but although everything is configured as described, the problem remains.

3

There are 3 answers

3
E. Rivera On

I think the bundle should only "read" the framework's header files but not build the sources and leave that task to the App (remove the Framework .m files from the UnitTest target).

Right now the App and the UnitTest are both building the Framework, thus the duplicated classes.

2
Sam On

You have added the dependency framework to the Tests target. This is flawed thinking. Since your primary application ALSO exports the SAME framework you will receive warnings about duplicated symbols for any classes found in the framework.

By removing your framework from the test target you can resolve the warnings. Remember, you're not losing any functionality by not linking against the same framework in the test target. Trust me, your code is still there.

0
Z S On

I ran into a similar problem here: Xcode5: creating new testing target

The key is to create a new unit testing bundle, point it to your original target, and then don't do anything else! If you start including frameworks and source files into the test target, it'll generate these linking errors. The test target is supposed to "inject" the test classes into the actual target, not create a new separate target on it's own. So you just need to import the header files in your test class, and write your test cases.