XCTest中的Swift TyphoonBlockComponentFactory错误

问题描述:

我正在使用Swift与Typhoon和Cocoapods。一切顺利,直到我开始编写Integrationtest(根据 Typhoon-Example-App Test )。我想在Test setUp()方法中设置 TyphoonFactory ,就像我在的AppDelegate 。当我执行测试时,我总是得到一个

i’m using Swift with Typhoon and Cocoapods. Everything worked well until i started to write an Integrationtest (according to the Typhoon-Example-App Test) for my Typhoon component. I wanted to setup the TyphoonFactory in the Test setUp() method in the same way as i did in the AppDelegate. When i execute the test i always get a


TyphoonBlockComponentFactory assertIsAssembly:] + 244:ERROR:MyApp.MyAssembly不是子类TyphoonAssembly

TyphoonBlockComponentFactory assertIsAssembly:] + 244: ERROR: MyApp.MyAssembly is not a sub-class of TyphoonAssembly

Typhoon引发的错误(使用 kindOfClass 方法引擎盖。)相同的代码在 AppDelegate 中完美运行,我无法弄清楚什么是错误的。

error thrown by Typhoon (wich is using the kindOfClass method under the hood.) The same code is working perfectly in the AppDelegate and i can’t figure out whats wrong.

为了验证这种行为,我实现了 isKindOfClass 签入展位类(见下面的代码):

To verify this behavior i implemented the isKindOfClass check in booth classes (see code below):


  • AppDelegate - > true

  • MyComponentTest - > false

  • AppDelegate -> true
  • MyComponentTest -> false

有人可以帮助我吗?
很多!

Can someone pls help me further? Thx a lot!

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
    }
}


为了其他用户的利益:

正如上所述a href =https://github.com/typhoon-framework/Typhoon> Typhoon的Github ,当Typhoon CocoaPod同时包含在app目标和测试目标中时,就会出现此错误。

As discussed over on Typhoon's Github, this error occurs when the Typhoon CocoaPod is included in both the app target as well as the test target.

由于应用程序样式的测试(设置了TEST_HOST标志)现在几乎无处不在,因此测试目标会自动从主应用程序目标继承依赖项。对于Swift,使用名称间距,如果它们在测试目标中重复,则事情可能会中断。

As application-style tests (with TEST_HOST flag set) are now the default almost everywhere, the test target automatically inherits dependencies from the main app target. In the case of Swift, with name-spacing, things can break if they're duplicated in the test target.

因此,解决方案是从测试目标中删除Typhoon以及应用程序的任何其他依赖项,因为这些是继承的。您仍然可以包含特定于测试的依赖项,如下所示:

Therefore the solution is to remove Typhoon, and any other of the app's dependencies from the test target as these are inherited. You can still include test-specific dependencies as follows:

target :tests, :exclusive => true do
   pod 'OCMockito'
   pod 'AnotherTestLibrary' #etc . . 
end