Swift TyphoonBlockComponentFactory Error in XCTest

im using swift with typhoon and cocopod. Everything worked fine until I started writing Integrationtest (according to Typhoon-Example-App Test ) for my Typhoon component. I wanted to set the TyphoonFactory in the Test setUp() method in the same way as in AppDelegate . When I run the test, I always get

TyphoonBlockComponentFactory assertIsAssembly:] + 244: ERROR: MyApp.MyAssembly is not a subclass of TyphoonAssembly

Typhoon error (using the kindOfClass method under the hood.) The same code works fine in AppDelegate , and I can't figure out what is wrong.

To test this behavior, I performed an isKindOfClass check in the stand classes (see code below):

  • AppDelegate -> true
  • MyComponentTest β†’ false

Can anyone help me? thanks 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 } } 
+5
source share
1 answer

In the interests of other users:

As discussed at Typhoon Github , this error occurs when Typhoon CocoaPod is included in both the target and the test target.

As application-style tests (with the TEST_HOST flag set), now almost everywhere by default, the test object automatically inherits dependencies on the main target of the application. In the case of Swift, with an interval between names, things can break if they are duplicated for a test purpose.

Therefore, the solution is to remove Typhoon and any other application dependencies from the test target, since they are inherited. You can still include test dependencies:

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

Source: https://habr.com/ru/post/1200668/


All Articles