iOS Unit Testing: Class is implemented in both

前端 未结 4 1562
甜味超标
甜味超标 2020-12-19 08:38

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 f

相关标签:
4条回答
  • 2020-12-19 09:16

    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
    
    0 讨论(0)
  • 2020-12-19 09:19

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

    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.

    0 讨论(0)
  • 2020-12-19 09:24

    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.

    0 讨论(0)
  • 2020-12-19 09:27

    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.

    0 讨论(0)
提交回复
热议问题