Nic Wanavit
Nic Wanavit

Reputation: 2693

unit test module import throws undefined symbol error

I am trying to import my class using this code

import XCTest
@testable import Test2

class Tests_iOS: XCTestCase {
    var test2:TestModule2!
    
    override func setUp() {
        let test2 = TestModule2()
    }
}

however xcode is throwing undefined symbol error

Undefined symbol: nominal type descriptor for Test2.TestModule2
Undefined symbol: type metadata accessor for Test2.TestModule2
Undefined symbol: Test2.TestModule2.__allocating_init() -> Test2.TestModule2

This doesn't happen with my older xcode 11 code using UIKit.

enter image description here

what is the cause of this error and how can I import modules correctly.

system specification

Mac M1 16GB
OS: Big Sur 11.4
Xcode: Version 13.0 beta (13A5154h)

Upvotes: 3

Views: 1953

Answers (1)

Patrick
Patrick

Reputation: 2422

If you created a multiplatform project, turns out that the default test target is a UI test and not a unit test. Try adding a new test target of type unit test. See this answer: https://developer.apple.com/forums/thread/665120

Upvotes: 5

Related Questions