Mockfile is a YAML configuration, allowing to define what gets mocked. It simplifies including and excluding sources, as well as defining what should be imported or
It also ties generated Mock configuration with a specific target, allowing to lint it agains most common issues.
Every generated file have its own section, following pattern below:
sourceryCommand: null # 1. mock1: # 2. sources: # 2.1. include: # 2.1.1 - ./MyApp exclude:  # 2.1.2 (optional) output: # 2.2 ./MyAppUnitTests/Mocks/Mock.generated.swift targets: # 2.3 (optional) - MyAppUnitTests testable:  # 2.4 (optional) import:  # 2.5 (optional) prototype: false # 2.6 (optional) sourcery: # 2.7 (optional) - ./path/to/custom/sourcery.yml # (optional) mock2: # 2. ...
sourceryCommandis by default
nil. You can use it to select custom Sourcery version/command/binary, instead of using default one bundled with SwiftyMocky CLI via
- Distinctive name of your mock configuration. You can define as much configurations as you want. Each of them represents one generated file. That allows to have a separate mocks for a separate targets (you usually need that if you have more than one test target)
sourcesdefines what files/directories would be scanned for
includelist of included files/directories relative to project root
excludelist of excluded files/directories relative to project root
outputlocation and name of generated mocks file. If no name specified
Mock.generated.swiftwould be used
targetslist of targets names. It should match the test targets that are using generated mocks file. Used to determine if your setup is correct.
testablelist of testable modules imports. By default, if you generate mocks for
YourApp, it should contain
YourApp. Would be placed at the top of the generated file.
importlist of modules imports. Would be placed at the top of the generated file.
trueif you are going to use Carthage
sourcerylist of paths to additional Sourcery configurations, if you want to execute them alongside the mock generation.
Note 1: Calling
swiftymocky setupwill launch an interactive tool helping you to create and prefill the Mockfile. You can also use
swiftymocky initif you want a placeholder you can fill manually.
Note 2: To evaluate your Mockfile setup, as well as other things, run
Note 3: You can use
swiftymocky autoimportto prefill
importin your configurations.