iOS Unit Testing: Class is implemented in both

做~自己de王妃 提交于 2019-11-28 03:51:16

问题


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?


回答1:


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.

import MyAppName



回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/33127896/ios-unit-testing-class-is-implemented-in-both

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!