Introducing Dejavu - the open-source network mocking library for swift developers

From time to time when writing tests in Swift you may encounter situations where network requests are needed as apart of test.

Network requests can cause tests to run slowly and make them more brittle due to potential network or service issues.

The team behind the ArcGIS Maps SDK for Swift implemented an internal tool that allows network requests in Swift tests to be recorded and played back during subsequent test runs. This capability takes network instability out of the equation and allows tests to run much more quickly and reliably.

This tool has been used for a few years with much success in stabilizing the tests and reducing failures. Recently we’ve taken the tool open-source making it available to any Swift developer – meet Dejavu.

Dejavu is already helping us in other areas. In our open-source toolkit we’ve used it to shave seconds of run time off of network dependent unit tests.

Dejavu is available now as a Swift package for use in your own Swift projects and applications.


Very cool, I actually had prototyped something similar recently, but for creating completely mocked requests (i.e. not recording). I ran into some difficulty with timing, as URLSession doesn't necessarily provide any guarantees about how partial data is treated (to be specific, URLProtocolClient methods don't map 1:1 with URLSessionTask callbacks). So when I mocked failure responses (like receiving some bytes of the response and then hanging for a period of time), I needed to empirically figure out a number of bits to transmit so that the URLSessionTask callback was actually called.

Have you run into this issue whilst developing Dejavu? And if so how did you solve it? I'd imagine when recording from the successful requests this doesn't really crop up easily.

1 Like

Hi @George, that sounds like an interesting prototype and also an interesting challenge to overcome. From what I know we didn't run into a similar issue.

1 Like