{"action":"created","issue":{"url":"https://api.github.com/repos/appsquickly/Typhoon/issues/394","labels_url":"https://api.github.com/repos/appsquickly/Typhoon/issues/394/labels{/name}","comments_url":"https://api.github.com/repos/appsquickly/Typhoon/issues/394/comments","events_url":"https://api.github.com/repos/appsquickly/Typhoon/issues/394/events","html_url":"https://github.com/appsquickly/Typhoon/issues/394","id":99196059,"number":394,"title":"Swift, PList Integration, Storyboard, XCTest - autowiring issues.","user":{"login":"achansonjr","id":883177,"avatar_url":"https://avatars.githubusercontent.com/u/883177?v=3","gravatar_id":"","url":"https://api.github.com/users/achansonjr","html_url":"https://github.com/achansonjr","followers_url":"https://api.github.com/users/achansonjr/followers","following_url":"https://api.github.com/users/achansonjr/following{/other_user}","gists_url":"https://api.github.com/users/achansonjr/gists{/gist_id}","starred_url":"https://api.github.com/users/achansonjr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/achansonjr/subscriptions","organizations_url":"https://api.github.com/users/achansonjr/orgs","repos_url":"https://api.github.com/users/achansonjr/repos","events_url":"https://api.github.com/users/achansonjr/events{/privacy}","received_events_url":"https://api.github.com/users/achansonjr/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-08-05T12:43:51Z","updated_at":"2015-08-05T15:30:59Z","closed_at":null,"body":"So first and foremost, thanks for a great DI framework. I am really enjoying using it.\r\n\r\nNow for the question.\r\n\r\nEnvironment:\r\nXCode-Beta\r\niOS 9\r\nUnit Test Framework: XCTest\r\nTyphoon Features Used: PList Integration, Storyboard Integration, Modular Assemblies\r\n\r\n```swift\r\nimport Typhoon\r\nimport CoreData\r\n\r\npublic class PersistenceTestAssembly : TyphoonAssembly {\r\n\r\n  var moc : NSManagedObjectContext\r\n  override init() {\r\n    do {\r\n      moc = try setUpInMemoryManagedObjectContext()\r\n    } catch {\r\n      exit(0)\r\n    }\r\n  }\r\n  \r\n  public dynamic func objectPAL() -> AnyObject {\r\n    return TyphoonDefinition.withClass(ObjectPAL.self) {\r\n      (definition) in\r\n      \r\n      definition.useInitializer(\"initWithMoc:\") {\r\n        (initializer) in\r\n        \r\n        initializer.injectParameterWith(self.moc)\r\n      }\r\n      definition.scope = TyphoonScope.Singleton\r\n    }\r\n  }\r\n}\r\n```\r\n\r\nSo this is the test specific assembly that I have set up to insert a test specific MOC for our data access objects (what we are calling PAL) here.\r\n\r\nIn the main application we are using PList integration, with a production version of the assembly above (as well as an application assembly) and everything works great. The storyboard is converted to a Typhoon storyboard, the controllers and associated stuff is injected properly. \r\n\r\nNow here is where I am having issues. I have created a plist for the test target, using the same values as the plist in the main target. I imagine that this is incorrect, however I figured that since the test target uses the appDelegate from the main target to run tests, it might be a good start. I didn't want to willy-nilly create a separate applicationTestAssembly in the test target as I didn't know if I could still tie that to the main targets appDelegate.\r\n\r\nWith this configuration I never could get the test target to initialize. Here is what I have managed to get working in my test using manual injection.\r\n\r\n```swift\r\nimport XCTest\r\n@testable import MainProject\r\nimport CoreData\r\n\r\nclass ObjectsTableViewCellTests: XCTestCase {\r\n\r\n  var uut: ObjectsTableViewCell!\r\n  var moc: NSManagedObjectContext!\r\n  var obj: Object!\r\n\r\n  override func setUp() {\r\n    super.setUp()\r\n    // Put setup code here. This method is called before the invocation of each test method in the class.\r\n    let storyboard = UIStoryboard(name: \"Main\", bundle: nil)\r\n    let assembly = PersistenceTestAssembly().activate()\r\n    let libraryController = storyboard.instantiateInitialViewController() as! LibraryViewController\r\n    let objectNavigationController = containerController.viewControllers?[0] as! UINavigationController\r\n    let objectsTableViewController = objectNavigationController.topViewController as! ObjectsTableViewController\r\n\r\n    objectsTableViewController.objectPAL = assembly.objectPAL() as! ObjectPAL\r\n    uut = objectsTableViewController.tableView.dequeueReusableCellWithIdentifier(\"ObjectCell\") as! ObjectsTableViewCell\r\n  }\r\n}\r\n```\r\n\r\nI have truncated the actual tests, but the crux of the issue is that this is the only way that I could get a typhoon created object in the assembly assigned to the specific controllers usually autowired variable.\r\n\r\nIs there a way to do this with plist integration?\r\n\r\nI tried to manually do it like so:\r\n\r\n```swift\r\nimport XCTest\r\n@testable import MainProject\r\nimport CoreData\r\n\r\nclass ObjectsTableViewCellTests: XCTestCase {\r\n\r\n  var uut: ObjectsTableViewCell!\r\n  var moc: NSManagedObjectContext!\r\n  var obj: Object!\r\n\r\n  override func setUp() {\r\n    super.setUp()\r\n    // Put setup code here. This method is called before the invocation of each test method in the class.\r\n    let bundle : NSBundle = NSBundle(forClass: ObjectsTableViewController.self)\r\n    let assembly = PersistenceTestAssembly().activate()\r\n    let factory : TyphoonComponentFactory = TyphoonBlockComponentFactory(assembly: assembly)\r\n    let storyboard = TyphoonStoryboard(name: \"Main\", factory: factory, bundle: bundle)\r\n    let containerController = storyboard.instantiateInitialViewController() as! ContainerViewController\r\n    let objectNavigationController = containerController.viewControllers?[0] as! UINavigationController\r\n    let objectsTableViewController = objectNavigationController.topViewController as! ObjectsTableViewController\r\n    objectsTableViewController.objectPAL = assembly.objectPAL() as! ObjectPAL\r\n    uut = objectsTableViewController.tableView.dequeueReusableCellWithIdentifier(\"ObjectCell\") as! ObjectsTableViewCell\r\n  }\r\n}\r\n```\r\n\r\nI assumed by creating the factory, and making storyboard an instance of TyphoonStoryboard that the plist integration might be picked up, but that is likely a false assumption as it would make sense that there is some larger lifecycle events that are happening surrounding the appDelegate insertion when Typhoon squirms its way in through the plist integration.\r\n\r\nWhat would you suggest that I do regarding wanting to use the autoinjection capability of Typhoon to autowire test specific dependencies using plist integration? I would really like to try and mimic the production features in my tests to ensure that version changes should I pick up a new version of the Pod won't break my use of the PList and Storyboard integration features.\r\n\r\nThanks for your time."},"comment":{"url":"https://api.github.com/repos/appsquickly/Typhoon/issues/comments/128040501","html_url":"https://github.com/appsquickly/Typhoon/issues/394#issuecomment-128040501","issue_url":"https://api.github.com/repos/appsquickly/Typhoon/issues/394","id":128040501,"user":{"login":"alexgarbarev","id":2268687,"avatar_url":"https://avatars.githubusercontent.com/u/2268687?v=3","gravatar_id":"","url":"https://api.github.com/users/alexgarbarev","html_url":"https://github.com/alexgarbarev","followers_url":"https://api.github.com/users/alexgarbarev/followers","following_url":"https://api.github.com/users/alexgarbarev/following{/other_user}","gists_url":"https://api.github.com/users/alexgarbarev/gists{/gist_id}","starred_url":"https://api.github.com/users/alexgarbarev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alexgarbarev/subscriptions","organizations_url":"https://api.github.com/users/alexgarbarev/orgs","repos_url":"https://api.github.com/users/alexgarbarev/repos","events_url":"https://api.github.com/users/alexgarbarev/events{/privacy}","received_events_url":"https://api.github.com/users/alexgarbarev/received_events","type":"User","site_admin":false},"created_at":"2015-08-05T15:30:59Z","updated_at":"2015-08-05T15:30:59Z","body":"Hello,\r\nPlist integration is not supported in unit tests, because there is completely different life cycle: in app we creating factory once at startup, then use across the app, in tests we have to create factory for each test.\r\n\r\nIf you want to test your ViewControllers with autowire feature, just create `TyphoonStoryboard` instead of `UIStoryboard` in your test (like in your latest snippet)\r\n\r\nif you want to test Typhoon's plist integration, you can create your factory using: \r\n```\r\nNSBundle *myTestBundle = [NSBundle bundleForClass:[MyTest class]];\r\nTyphoonBlockComponentFactory *factory = [TyphoonBlockComponentFactory factoryFromPlistInBundle:myTestBundle];\r\nTyphoonStoryboard *storyboard = [TyphoonStoryboard storyboardWithName:@\"Main\" factory:factory bundle:myTestBundle];\r\n```\r\n_(please convert that code into swift)_\r\n\r\nBut if you afraid that Plist integration would be broken in future `Typhoon` version, we have unit tests for that case (Current coverage of TyphoonStartup class is 76%, TyphoonInitialStoryboardResolver: 88%)\r\nIf you find these tests not useful, please add your unit tests into Typhoon and create PullRequest. (we will be happy)"}}