Writing testable UI related code with modern Swift

We ran into something similar when testing for the ImmutableData [full discolsure: self promotion] project. What we were looking for was something like an AsyncSequence with backpressure that also blocked on yield. The AsyncAlgorithms.AsyncChannel came close… but yield was async backpressure was applied after the for await was already started.

We ended up building our own AsyncSequence just for testing and then injecting that AsyncSequenceTestDouble at compile time with dependency injection in our tests. You can see for yourself how we use this AsyncSequenceTestDouble in our ImmutableData test code. This might give you some ideas how something similar might be used in your own tests.