I have a unit test that needs to access internal methods/properties on a module imported by my application target.
E.g.
SubModule.swift
public class SubModuleType {
...
internal let value: InternalSubModuleType
...
}
AppViewController.swift
import SubModule
// do things with SubModuleType
AppViewControllerTests.swift
@testable import App
@testable import SubModule
func testWithSubModule() {
let internalSubModuleTypeInstance = SubModule.SubModuleType().value
// ... run a test dependent on internalSubModuleTypeInstance
}
In this test I receive 'Use of undeclared type 'InternalSubModuleType'' when accessing .value
.
- I have added the
SubModule
target toApp-Tests
"Target Dependencies" - I have set "Enable Testability" to YES for both the App target and SubModule target for the scheme I'm compiling for testing.
@testable import
is supposed to allow you to access types marked internal under these conditions. I'm not sure why I'd be receiving this compiler error. I can still use any type that is marked internal in my App target by using @testable
but not my SubModule target.
Are you only allowed 1 target to be @testable import
in a test target or is there something I'm missing?
using Xcode 9, Swift 3.2
Recreating the Testing target seemed to have done the trick for me.
Simply delete your old Testing target, create a new one and add this target to all the testing files that you have.