iOS unit testing with URLSessionClient

Hello,

We have integration unit tests that involve GraphQLClient with mocking URLProtocol and it works well for the most part.

However we are getting crashes in URLSessionClient because of the assertion in urlSession(:dataTask:didReceive)

The issue is when the test ends we deallocate everything and invalidate() is called, the tasks array is cleared. If there was a task inflight the URLSessionDelegate method does eventually called and it would go into the assertion.

What is the best approach here? Should I subclass URLSessionClient and have my own implementation for testing? Would passing in a custom URLSessionConfiguration fix the issue? (although I don’t know if that will solve the inflight task problem)

Any suggestions are appreciated

Thanks

  • Ketenshi