1

I'm trying to call a swift singleton from my UITest target. I'm importing the main module: @testable import Ary but when I try to build it says:

Undefined symbols for architecture armv7:
  "Ary.DataModelLayerOperation.getter : Ary.DataModelLayer", referenced from:
      AryUITests.AryUITests.setUp (AryUITests.AryUITests)() -> () in AryUITests.o

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

Syntax highlighting works though (the singleton doesn't have access modifiers, so it's marked as internal which should be perfectly fine for access from the test target)...

The function I'm calling is [in an XCTestCase]:

 override func setUp() {
    super.setUp()
  if !DataModelLayerOperation.isUserLoggedIn() {
    //do something
  }
}
vale
  • 1,376
  • 11
  • 25
  • I don't know if this will help as I haven't had need to do this yet but there is a way to share code between UITest and the project targets. The example I saw wasn't really for this purpose but if it's a singleton maybe the entire class code could be shared with UITest. It would still be separate from the app but perhaps could be used for some kind of mocking? https://www.bignerdranch.com/blog/ui-testing-in-xcode-7-part-1-ui-testing-gotchas/#gotcha-sharing-code-between-app-and-ui-tests (I'm not sure if I'm supposed to comment on the question or accepted answer so I did both). – Abbey Jackson Dec 23 '15 at 22:38

1 Answers1

2

I'm afraid what you want to achieve is not possible at the moment. I have encountered similar problem and asked my question here. I will soon accept the answer that says:

The UI tests are a separate module from the app, therefore not run inside your app as a logic test would.

I'm hoping this will be improved in the next Xcode versions.

Community
  • 1
  • 1
lawicko
  • 7,246
  • 3
  • 37
  • 49
  • I don't know if this will help as I haven't had need to do this yet but there is a way to share code between UITest and the project targets. The example I saw wasn't really for this purpose but if it's a singleton maybe the entire class code could be shared with UITest. It would still be separate from the app but perhaps could be used for some kind of mocking? https://www.bignerdranch.com/blog/ui-testing-in-xcode-7-part-1-ui-testing-gotchas/#gotcha-sharing-code-between-app-and-ui-tests (I'm not sure if I'm supposed to comment on the question or accepted answer so I did both) – Abbey Jackson Dec 23 '15 at 22:37
  • Also I don't think there is anything to "improve" about it. What Apple has done is totally different than prev ways. Adding this would be great, I agree, but what Apple has done is designed a UITest system that tests UI only. UI is only what you SEE not the code inside the app. It's like if a driver is checking that a car turns properly. The driver turns the steering wheel and it turns, they don't check that the axel is there, that's the mechanic's job. It's just a different way of compartmentalizing. I suspect 3rd party tools that mock UI rather than use UI as UITest does will remain popular. – Abbey Jackson Dec 23 '15 at 22:43