Skip to content

Fixing #47 : Stubs not called when using Application/UI Tests

Compare
Choose a tag to compare
@AliSoftware AliSoftware released this 09 Jan 20:57
· 580 commits to master since this release

Fixing issue #47 when stubs were not called, especially when the OHHTTPStubs pod were loaded both by the application AND the test target in the Podfile (thus loaded in both the app and test bundle).

See also the dedicated article: A tricky case with Application Tests.


In details:

  • NSURLSessionConfiguration 's swizzling (to add automatic support of OHHTTPStubs to NSURLSession) is now done in the +load method of an NSURLSessionConfiguration category, to be sure it is loaded (and swizzled) only once, even if OHHTTPStubs is loaded by two different bundles.
  • The stubs activation of NSURLSessionConfiguration no longer uses objc_getClass but uses a call to the OHHTTPStubs class instead, which ensure that it uses the correct OHHTTPStubs class in the current bundle instead of always using the one loaded from the main bundle.