You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hey, this is a really cool DI utility and I am using it on pretty much all my projects now.
One thing the DI really helps with is to allow test fixture to inject mock databases, network, etc. for apps to test internal functionality without external dependencies.
When I have an iOS app that's configured with a SwinjectStoryboard (swift) class like this:
...and I want to register my data provider like this example
defaultContainer.register(DataModel.self) { _ in RealmServerModel() }
.inObjectScope(.container) //make it a singleton
but I want to write unit tests in my tests target that instantiate ViewControllers using the storyboard
let container = Container()
container.register(DataModel.self) { _ in TestRealmDataModel.self() }
let testDataModel = container.resolve(DataModel.self) as! TestRealmDataModel
let storyboard = UIStoryboard(name: "Main", bundle: nil)
describe("ViewController") {
var vc: ViewController!
beforeEach {
vc = storyboard.instantiateViewController(withIdentifier: "ViewController") as! ViewController
...what I find is that the SwinjectStoryboard runs first, before my test fixture gets in there to create a container to register the model class for testing.
My workaround has been to avoid running the code in SwinjectStoryboard if it's running tests, like so:
if ProcessInfo.processInfo.environment["XCTestConfigurationFilePath"] == nil {
// Code only executes when tests are not running
Is there a more elegant way that this could be done?
The text was updated successfully, but these errors were encountered:
Hey, this is a really cool DI utility and I am using it on pretty much all my projects now.
One thing the DI really helps with is to allow test fixture to inject mock databases, network, etc. for apps to test internal functionality without external dependencies.
When I have an iOS app that's configured with a SwinjectStoryboard (swift) class like this:
...and I want to register my data provider like this example
but I want to write unit tests in my tests target that instantiate ViewControllers using the storyboard
...what I find is that the SwinjectStoryboard runs first, before my test fixture gets in there to create a container to register the model class for testing.
My workaround has been to avoid running the code in SwinjectStoryboard if it's running tests, like so:
Is there a more elegant way that this could be done?
The text was updated successfully, but these errors were encountered: