Linker error when accessing application module in UI tests in Xcode 7.1

前端 未结 3 1181
野的像风
野的像风 2020-12-08 07:26

I\'m trying to implement some UI tests in my project. Everything goes fine as long as I keep it simple: record the test case, add some asserts, then run the test. This works

相关标签:
3条回答
  • 2020-12-08 07:53

    The UI tests are a separate module from the app, therefore not run inside your app as a logic test would. The only way for them to share code is to compile in all the app files you need to share between the two modules. Check this blog for how you can achieve that, https://www.bignerdranch.com/blog/ui-testing-in-xcode-7-part-1-ui-testing-gotchas/

    Also found a radar filed here, https://openradar.appspot.com/23116258

    0 讨论(0)
  • 2020-12-08 07:54

    @testable import <yourApp> could actually be causing this bug. Just take out the line. It isn't needed for UI Tests.

    "UI tests run outside your app in a separate process. You can’t access app code from inside a UI test - that’s intentionally part of the design. Use unit testing for tests that need to access the app code and UI tests to automate user interaction testing"

    Notice at 6 minutes in, @testable isn't used by Apple Developers. https://www.youtube.com/watch?v=7zMGf-0OnoU&t=1316s

    0 讨论(0)
  • 2020-12-08 07:57

    @testable import MainModule won't work for UI test, though it would enable code completion (may make you feel it works). It's designed only for unit test so far. And it would lead to build failure, something like:

    ld: symbol(s) not found for architecture x86_64
    clang: error: linker command failed with exit code 1 (use -v to see invocation)
    

    The workaround is to add the source code file to UI test target as well, then it will work out of the box (even without @testable import).

    File Inspector -> Target Membership -> check UI test target (in addition to main target)

    Hope Apple will fix it soon so that we can have a cleaner way to use it.

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