Swift TyphoonBlockComponentFactory Error in XCTest
Asked Answered
O

1

5

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 is not a sub-class of TyphoonAssembly

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.

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

  • 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
    }
}
Orban answered 19/8, 2014 at 11:32 Comment(3)
Your class is MyAssembly or ONETyphoonAssembly? Can you raise a GitHub issue and submit sample code? . . we're still working on Swift support.Breeches
Done: Typhoon IssueOrban
Thx to TyphoonGroup i solved the problem by removing the Typhoon dependency from the PodFiles "MyAppTests" section. For more details see Typhoon-IssueOrban
B
7

For the benefit of other users:

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.

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.

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
Breeches answered 20/8, 2014 at 11:58 Comment(2)
The same solution for OCMock.Grazing
Once again Jasper you rock! This is the correct answer and instantly solved my issue :)Standby

© 2022 - 2024 — McMap. All rights reserved.