Swift Mocking Tools. To Use, or Not to Use, That Is the Question

This page summarizes the projects mentioned and recommended in the original post on /r/u_Evolvice

Our great sponsors
  • WorkOS - The modern identity platform for B2B SaaS
  • InfluxDB - Power Real-Time Data Analytics at Scale
  • SaaSHub - Software Alternatives and Reviews
  • OCMockito

    Mockito for Objective-C: creation, verification and stubbing of mock objects

  • Everything would be smooth and easy, except that Swift is not Objective-C. Supplying test doubles is incredibly easy in Objective-C, where the central mechanism is messages. You could send any message to any object. In case you had previous experience mocking on Objective-C using OCMock or OCMockito — forget it.

  • Cuckoo

    Boilerplate-free mocking framework for Swift! (by Brightify)

  • Additional setup: The cuckoo installation process requires adding a new run script into your test target build phases. Include the absolute path to each file and the framework that will generate mocks in this script. Import the generated file into the project once, and then re-generate it to keep it up to date. Class name starts from the word ‘Mock’ — each test double you can use as mock, stub, or spy.

  • WorkOS

    The modern identity platform for B2B SaaS. The APIs are flexible and easy-to-use, supporting authentication, user identity, and complex enterprise features like SSO and SCIM provisioning.

    WorkOS logo
  • SwiftyMocky

    Framework for automatic mock generation. Adds a set of handy methods, simplifying testing. One of the best and most complete solutions, including generics support and much more.

  • Additional setup: SwiftyMocky has a 2 step installation. First, set up SwiftyMocky CLI on your working machine. Second, add it to the project’s test target via one of the 3 options listed above. Open Terminal in your project root folder and execute the following commands one by one:

  • SwiftMockGeneratorForXcode

    An Xcode extension (plugin) to generate Swift test doubles automatically.

  • Spoiler! It’s not a library but an Xcode plugin that helps solve the same problem — generating test doubles. SwiftMockGeneratorForXcode is an exception in this list of frameworks. Instead of being integrated into the project, this generator can only be added as an extension to Xcode. Also, you won’t have any custom verifiers or matchers, do all assertions using the XCTest framework.

NOTE: The number of mentions on this list indicates mentions on common posts plus user suggested alternatives. Hence, a higher number means a more popular project.

Suggest a related project

Related posts