我正在使用Swift、Typhoon和Cocoapods。一切都很顺利,直到我开始为我的Typhoon组件编写集成测试(根据Typhoon-Example-App Test)。我想在测试的
“PodFile”
setUp()
方法中设置TyphoonFactory
,就像我在AppDelegate
中所做的那样。当我执行测试时,我总是会得到一个由Typhoon抛出的错误:
TyphoonBlockComponentFactory assertIsAssembly:] + 244: ERROR: MyApp.MyAssembly不是TyphoonAssembly的子类
Typhoon使用kindOfClass
方法来实现此功能。相同的代码在AppDelegate
中运行完美,但我无法确定问题所在。
为了验证这种行为,我在两个类中实现了isKindOfClass
检查(请参见下面的代码):
- AppDelegate -> true
- MyComponentTest -> false
“PodFile”
inhibit_all_warnings!
target "MyApp" do
pod 'Typhoon', '2.1.0'
end
target "MyAppTests" do
pod 'Typhoon', '2.1.0'
end
MyAssembly.swift
public class MyAssembly : TyphoonAssembly{
//Some definitions
}
AppDelegate.swift
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: NSDictionary?) -> Bool {
…
var assembly : MyAssembly = MyAssembly()
//Always returns „true“
println("Is type of class: \(assembly.isKindOfClass(TyphoonAssembly))")
…
}
MyComponentTest.swift
import XCTest
import MyApp
class MyComponentTest: XCTestCase {
override func setUp() {
super.setup()
var assembly : MyAssembly = MyAssembly()
//Always returns „false“!
println("Is type of class: \(assembly.isKindOfClass(TyphoonAssembly))")
//Error is thrown „MyApp.MyAssembly is not a sub-class of TyphoonAssembly“
var factory : TyphoonComponentFactory = TyphoonBlockComponentFactory(assembly: assembly) as TyphoonComponentFactory
}
}