【问题标题】:Swift Typhoon error in tests target - not subclass of Typhoon Assembly测试目标中的 Swift Typhoon 错误 - 不是 Typhoon Assembly 的子类
【发布时间】:2014-12-16 13:29:00
【问题描述】:

我正在尝试使用示例项目设置 Typhoon 框架,当我运行模拟器时它工作正常,但当我尝试运行测试时它给了我一个错误。错误如下:

NSInvalidArgumentException',原因:'Class 'DI_Example.MyAssembly' 是 不是 TyphoonAssembly 的子类'

现在,我读到herehere,这是由于 CocoaPods 导致 Typhoon 包被链接两次造成的。所以这是我的 Podfile,它似乎不应该链接两次

platform :ios, '8.0'

target 'DI_Example', :exclusive => true do
    pod 'Typhoon', '~> 2.3' end

target 'DI_ExampleTests', :exclusive => true do end

inhibit_all_warnings!

此外,当我将测试目标从应用程序样式更改为逻辑样式时,一切似乎都运行良好(我假设是因为包没有导入两次)。谁能发现我在做什么的问题?

似乎在我的测试之前就抛出了错误,所以我猜它与链接两个目标有关

这是我的测试(如果我将主机 Application 设置为 None

var controller: HomeViewController!
override func setUp() {
    super.setUp()
    let ctrlAssembly = ControllersAssembly()
    let blAssembly = BusinessLogicAssembly()
    ctrlAssembly.blAssembly = blAssembly
    let factory = TyphoonBlockComponentFactory(assemblies: [blAssembly, ctrlAssembly])
    let configurer = TyphoonConfigPostProcessor()
    configurer.useResourceWithName("Info.plist")
    factory.attachPostProcessor(configurer)


    controller = factory.componentForKey("homeViewController") as HomeViewController
}

func testControllerTitle() {
    // Arrange

    // Act
    controller.viewDidLoad()

    // Assert
    println(controller.title)
    XCTAssertTrue(controller.title == "Root View", "Title is set")
}

【问题讨论】:

  • 您提到它“似乎”不像台风依赖项被链接了两次。您可以通过检查测试目标的 Build Phases 选项卡来验证吗?您应该会在“Link Binary With Libraries”下看到链接的库
  • 它表示测试目标为“0 项”,应用程序目标为 libPods.a 的“1 项”
  • 我在两个目标的配置中重复使用相同的 Pods-DI_Example.debug.xcconfig 但如果我没有为测试目标指定一个,它将找不到 Typhoon 文件
  • 嗯.. 我的理解是 Pods-DI_ExampleTests.xcconfig 应该根据您的 podfile 的设置方式在其中包含 Typhoon。可以打开config看看是不是这样吗?
  • 我不明白它到底做了什么,但这里是 GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1 HEADER_SEARCH_PATHS = "${PODS_ROOT}/Headers/Public" "${PODS_ROOT}/Headers/Public /Typhoon" OTHER_CFLAGS = $(inherited) -isystem "${PODS_ROOT}/Headers/Public" -isystem "${PODS_ROOT}/Headers/Public/Typhoon" OTHER_LDFLAGS = -ObjC -l"Pods-DI_Example-Typhoon" OTHER_LIBTOOLFLAGS = $(OTHER_LDFLAGS) PODS_ROOT = ${SRCROOT}/Pods

标签: ios swift cocoapods typhoon


【解决方案1】:

所以我设法解决了这个问题。问题是因为我对测试目标没有任何依赖关系,所以我没有Pods-PocketForecastTests.debug.xcconfig,所以在我的项目配置中,我使用了与应用目标相同的配置文件,我猜这会导致它被链接两次。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多