3

I have unit test (not UI tests) and launching app itself along with tests is undesirable. I read about so-called non-hosted tests and that sounds suitable here. However, trying to launch non-hosted test on Xcode 7.3 I faced one serious problem - it complains that classes in app being tested couldn't be found by linker.

What I have read and tried:

App delegate substitution based on launch arguments - undesirable since it forces my app to know about tests (tight coupling, broken encapsulation etc...) and actually launch my app along with test (even though doing nothing)

XCode 5 unit testing: starts my app - tried every answer here and they don't work except changing classes target membership which is obviously not a good option since changing target membership manually is error-proned and becomes difficult when project grows

Apple's outdated guide - nope

Xcode test target with host application forces wrong target into build section of scheme - nope

https://stackoverflow.com/a/22024428/2305175 - nope

Manually creating unit test target with explicitly setting Target to be tested to None - nope

How could I run non-hosted tests without changing classes target membership, app delegate substitution and other questionable techniques???

Community
  • 1
  • 1
Fyodor Volchyok
  • 5,610
  • 4
  • 28
  • 45

1 Answers1

0

You can achieve this by using xctool with xCode 7

  1. First go to your test target settings.
  2. Go to general tab
  3. Select None as Host Application
  4. Then install xctool from terminal
  5. Run the tests from terminal as follows,

    xctool -workspace test.xcworkspace -scheme testScheme run-tests -sdk iphonesimulator

rustylepord
  • 5,681
  • 6
  • 36
  • 49
  • 1
    Unfortunately, doesn't work. BTW how would it if it xctool uses the same tools that xcode (if i understand correctly)? – Fyodor Volchyok May 28 '16 at 07:36
  • What part does not work ? Did you build the project using xctool and run it first ? Does it failed to build ? or does it run . xctool is a replacement for xcodebuild. Please be more specific. – rustylepord May 29 '16 at 03:55
  • Yes, I tried to build with xctool with no success. I got error stated in my question - "classes in app being tested couldn't be found by linker". To be more concrete, "Undefined symbols for architecture i386: (long list of functions in main target classes referenced from test classes)" Compiler see my test classes (i.e. SomeClassTest: XCTestCase), but not classes in app (SomeClass being tested and located in main target). My main target (SomApp) compiles successfully, but not tests (SomAppTests). – Fyodor Volchyok May 29 '16 at 06:54
  • xCode is correct , to run the tests in a non hosted manner you have to ilnk your app classes against which you reference / test from your unit tests. You can try the solutions in this post as well, http://stackoverflow.com/questions/19219706/xcode-5-unit-testing-starts-my-app?lq=1. Also you can try with a small POC before working without main app. – rustylepord May 29 '16 at 07:24
  • http://stackoverflow.com/questions/19219706/xcode-5-unit-testing-starts-my-app?lq=1 is NOT a good option and I said why in my question. And what do you mean by POC? – Fyodor Volchyok May 29 '16 at 08:08