Even then, I think people turn to mocking too quickly without considering approaches like isolating more of their core logic or standing up a mock server.
Yes, yes, 100 times this. I could not agree more. How can this "new direction for testing" smooth the way to things like "standing up a mock server." I am looking for examples that do that using this new system. We desperately need to mock less, inject less, and test the real code against the thinnest abstraction layers we can so we can see the bugs that come from the interactions. And a new direction for testing document should show what that might look like.
Network interactions are a great example. I would imagine things like:
#networkProxy(when: "https:*/get/user/bob", return: makeRecord("bob").json)
@Test func testFetchBob() {
#expect(await myService.get(user: "bob") == makeRecord("bob"))
}
Obviously that's a bikeshed kind of syntax, and building it well is very hard. But to call it a new direction it should engage with this kind of real problem. What would solutions even look like? How can the language enable frameworks that enable this?
Every day I face code that is not perfectly isolated for testing, about 50% because I didn't do it right, about 50% because Apple didn't do it right. I can't fix much of the first, and I can't fix any of the second. A testing direction has to engage with that. Something really basic: sometimes you have to poll. I need to be able to say things like:
#expect(within: .seconds(1), that: await service.status == "done")
And I need that to work even when service provides no way to observe it. Yes, that probably, horribly, means polling. I need polling.
Swift is at its best when it reimagines things in a brand new way. I don't want to copy one of the thousand mocking frameworks. I want a new answer, not just a more elegant syntax for the same limitations.