[Accepted] A New Direction for Testing in Swift

I didn't mention mocking in the vision document, and perhaps I should have because I agree it can be useful in some testing scenarios and it's a topic many people mentioned in our initial forum post about swift-testing. I also feel it's a technique which can sometimes be overused and lead to a false sense of security or other problems if poorly applied. Nevertheless, in my opinion there should eventually be some better approach for mocking that feels idiomatic in Swift, whether it be via something built-in to the language/runtime, better tools or macros for generating mocking code, or some combination.

So far, those of us contributing to swift-testing have focused on what we consider the fundamentals of a modern testing library: declaring tests, validating expected conditions, enabling common behaviors (mostly via built-in traits), and integrating with tools. Over time, we hope to add more advanced features and functionality, some of which the vision document covers. I think mocking could potentially be on that roadmap too, but unlike the other topics the vision mentions, there isn't yet consensus about what the ideal solution for mocking in Swift should be, and it's a complicated problem to solve well. That's why I didn't mention mocking in the document: not that we don't think it's important, but that we don't have anything specific to propose on the topic right now.

12 Likes