Martin
Martin

Reputation: 1143

Undefined symbols for architecture x86_64 testing my ViewController Swift

I'm actually trying to implement UI testing in my application with nimble-snapshot. I'm facing a issue that I don't really understand. I have been looking around but don't seems to find an answer to my problem.

My problem occurs when I try to instantiate my viewcontroller to try and test the view associated with it.The compilation always fails with this error message.

Undefined symbols for architecture x86_64:
"__T06medici19LoginViewControllerCMa", referenced from:
__T013mediciUITests13LoginViewTestC4specyyFyycfU_yycfU_ in 
testUILogin.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

My test code looks like this:

import Nimble
import Nimble_Snapshots
import Quick
import UIKit

@testable import XXXXMyProject

class LoginViewTest: QuickSpec {

override func spec() {

    describe("LoginView") {
        var vcLogin: LoginViewController!

        beforeEach {
            let storyboard = UIStoryboard(name: "Account", bundle: nil)
            vcLogin = storyboard.instantiateViewController(withIdentifier: "LoginViewController") as! LoginViewController
            _ = vcLogin.view // To call viewDidLoad
        }

        it("has a valid snapshot") {

            expect(vcLogin.view) == recordSnapshot()
        }
    }
  }
}

Being quite new to UI testing I don't really understand what is causing this issue. Any help or tips would be greatly appreciated on how to resolve this problem or improve my ui testing code.

Thank you in advance.

Martin

Upvotes: 4

Views: 2240

Answers (1)

Michal Cichon
Michal Cichon

Reputation: 1409

UI tests cannot use your application internals. To test it please use Unit Tests, but make sure that the "Allow testing Host Application APIs" option in your Unit Tests target > General is checked.

Upvotes: 7

Related Questions