7

I'm building an iOS 9 App with Swift 2 and Xcode 7.

My app runs fine when deploying it to my phone but when I run any unit test, I get the following error message for a lot of classes:

Class _TtC5<AppName>19<ClassName> is implemented in both /Users/<Username>/Library/Developer/CoreSimulator/Devices/<UUID>/data/Containers/Bundle/Application/<UUID</<AppName>.app/<AppName> and /Users/<Username>/<Path/To/Workspace>/DerivedData/<AppName>/Build/Products/Debug-iphonesimulator/<AppName>.xctest/<AppName>. One of the two will be used. Which one is undefined.

Any ideas?

ricardopereira
  • 11,118
  • 5
  • 63
  • 81
fancy
  • 2,077
  • 2
  • 23
  • 45

4 Answers4

7

Only add the test class to your test target and none of the iPhone app classes. Then simply import your app name as a module on top of your test class to get access to all app classes.

@testable import MyAppName
Mundi
  • 79,884
  • 17
  • 117
  • 140
  • 2
    This just not working for me - I used "@import AppName;" - is the syntax different than this? – David H Apr 28 '16 at 15:16
  • Had same warning for macOS unit tests. To fix, had to remove the files from the test target as mentioned - thanks. But "import MyAppName" did not work, instead had to use the "@testable" decorator as well "@testable import MyAppName". – shufflingb May 31 '22 at 12:13
  • Correct, @testable is now a requirement. Added it. – Mundi Jun 02 '22 at 13:25
4

Duplicated class implementations while running the test suite: in my case, since the test target has a host app, you don’t need to link the third-party frameworks. I had to clean the "Other Linker Flags" (OTHER_LDFLAGS) from Build Settings because it was linking to all CocoaPods of the workspace.

ricardopereira
  • 11,118
  • 5
  • 63
  • 81
2

The answer by @Mundi is correct for some cases.

However, I experienced the same error and what was causing it is that the libPods.a file for Cocoa Pods was being linked in the app target and the test target.

Roberto
  • 3,487
  • 1
  • 22
  • 24
2

I had the same error with an XCTest. Remember to select Allow testing Host Application APIs.

enter image description here

Then inside of Build Phases for your XCTest Target - like others have said - make sure you have zero files in Compile Sources that are already compiled in the Host Application.

rustyMagnet
  • 3,479
  • 1
  • 31
  • 41