>我正在尝试为 swift 应用程序编写测试用例,但我无法从测试文件夹访问主要目标类
这是我的 Pod 文件
target 'ProjectName' do
use_frameworks!
pod 'SwiftyJSON'
pod 'Alamofire', '~> 4.6'
pod 'Firebase/Core'
pod 'Firebase/Auth'
pod 'GoogleSignIn'
pod 'FBSDKLoginKit'
pod 'TwitterKit'
target 'ProjectNameTests' do
inherit! :search_paths
end
target 'ProjectNameUITests' do
inherit! :search_paths
end
end
我的测试用例在这里
import XCTest
import Foundation
@testable import ProjectName
class SimpleTests: XCTestCase {
func test1(){
var a = Profile();
}
}
Profile
类位于主目标中,我可以看到这个类,但是运行后出现此错误
Undefined symbols for architecture x86_64:
"__T013ProjectName7ProfileCMa", referenced from:
__T018ProjectNameTests06SimpleC0C5test1yyF in ProjectNameTests.o
"__T013ProjectName7ProfileCACSS10jsonString_tcfC", referenced from:
__T018ProjectNameTests06SimpleC0C5test1yyF in ProjectNameTests.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
如果我删除行var a = Profile()
,测试正在工作
您还需要在测试类中导入框架。 例如,如果您想在测试类中使用 SwiftyJSON 功能。
你需要写——
import SwiftyJSON