Skip to content

Not working with URLSessionConfiguration.background #97

@NeverwinterMoon

Description

@NeverwinterMoon

It looks to be similar to: #50 which was marked as fixed.

I have a SessionManager initialized as a singleton and then used in the service under test. I first stub everything with Mockingjay and then call one of the service's methods, this in turn makes a request using Alamofire SessionManager. And the real request goes through.

Now, if I don't use the singleton SessionManager and create it inside the test, then pass it to the service under test, then Mockingjay stubbing works.

Interestingly enough, in the original scenario, the SessionManager singleton is actually only called (so, initialized) for the first time in the service under test (I don't use the real AppDelegate in unit tests), meaning (I might still be wrong on this though) that the stub is called before the SessionManager is even created and still this fails to work...

Xcode 9.3
Swift 4.1
Alamofire 4.7.2
Mockingjay 2.0.1

EDIT

OK, this is more clear now. It's not about just SessionManager, but about the manager using non-default configuration:

static let sessionManager: Alamofire.SessionManager = {
    let configuration = URLSessionConfiguration.background(withIdentifier: "XXX")
    configuration.timeoutIntervalForRequest = 60

    return Alamofire.SessionManager(configuration: configuration)
  }()

When not using background configuration, stubbing works.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions