Parrot is a compile-time Mock Generator for Swift - written completely in Swift. It's geared towards use in Xcode and works for any kind of swift project (e.g. server side, iOS, or command line tools). The mock structure is modeled off of the sinon.js APIs
Clone or download
bdlindsay Merge pull request #8 from MonsantoCo/protocol-composition-7
allows internal modifier on protocols, supports protocol composition,…
Latest commit 06b8430 Nov 5, 2018
Type Name Latest commit message Commit time
Failed to load latest commit information.


Adding to a Project

Command Line(assuming in base of project directory):

git submodule add

cd Parrot

git submodule update --init

  • Open the Parrot xcode project and select a signing certificate (the next step will fail if a valid signing certificate is not selected)


Open project

  • Go to Project File
  • Select the target for your unit tests
  • Select 'Build Phases'
  • Select '+' -> 'New Run Script'
  • Drag the run script to be before the 'Compile Sources' step, but after the 'Target Dependencies' step
  • Example Script (Bash):

if [ -f "$PARROT" ]; then
    echo "💚 Running Parrot - SQUAAWWWKKKK 💚"
    $PARROT $SOURCE $TESTS || exit 0
    echo "⚠️ xcodebuild gitsubmodule Parrot to enable mock generation"


  • Add the annotation //@@parrot-mockabove any class definition conforming to a protocol somewhere in the project (protocols defined inside frameworks will not be found yet)
  • Example:
@testable import [AppName] // All lines above the annotation will be preserved

class MockClass: ClassProtocol {

  • When your test target builds, a mock will be generated before compile time

Non-Basic and Custom Types:

  • If you use types like UUID or Date you'll see that Parrot doesn't know how to generate instantiations for these types or any of your custom classes and structs. It will just leave placeholders in generated mocks. parrot-defaults.swift is the solution for telling Parrot how to instantiate types it wouldn't otherwise know how to create.
  • Add a file called parrot-defaults.swift to the base of your test directory.
  • Each line can teach parrot how to instantiate a type by defining a variable with an explicitly named type and then proceeding to instantiate that type. (e.g. let parrotUUID: UUID = UUID(), "let anyCustomType: CustomType = CustomType()")
  • Parrot will always check this list first before generating a mock so if you want to override some of the defaults for basics types, you can do that as well. let newIntDefaultValue: Int = 1 will make all Int types instantiate to 1 instead of 0 in your mocks.
  • Friendly Reminder: Don't forget to have appropriate import statements both in parrot-defaults.swift and your mocks.