Reputation: 10283
I've just added some unit tests to a new project. Normally I use @testable import
to import the production code, so I can test non-public methods:
@testable import My-Project
import XCTest
final class MyTests: XCTestCase {
func testOne() {
// ...
}
}
However I'm seeing some strange compilation errors, which I've never seen before:
Tests.swift:1:25: Consecutive statements on a line must be separated by ';'
Tests.swift:1:25: Expected expression after unary operator
Tests.swift:1:25: Expressions are not allowed at the top level
Tests.swift:1:18: No such module 'My'
I've checked and double checked everything and just cannot work out why this compilation error is produced.
What am I missing?
Upvotes: 3
Views: 683
Reputation: 540055
Project and target names can contain special characters (like spaces or dashes), but module names can not. By default, Xcode generates the module name from the target name by replacing invalid characters with an underscore.
Therefore, in your case
@testable import My_Project
would fix the issue. Alternatively, assign a custom “Product Module Name” in the build settings of the target.
There is no need to rename the entire project (or target).
Upvotes: 4
Reputation: 10283
The project name (and therefore internal module name) contains a dash (-) character.
To fix this:
@testable import ...
statement to reflect the new module nam.Upvotes: 0