Mockfile format
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 @testable imported.
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)
mock2: # 2.
...
sourceryCommandis by defaultnil. You can use it to select custom Sourcery version/command/binary, instead of using default one bundled with SwiftyMocky CLI viamint.- 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 forAutoMockabletypes.includelist of included files/directories relative to project rootexcludelist of excluded files/directories relative to project root
outputlocation and name of generated mocks file. If no name specifiedMock.generated.swift
would be usedtargetslist 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 forYourApp, it should containYourApp. Would be placed at the top of the generated file.importlist of modules imports. Would be placed at the top of the generated file.prototypedefault isfalse. Settrueif you are going to use CarthageSwiftyPrototypelibrary
Note 1: Calling
swiftymocky setupwill launch an interactive tool helping you to create and prefill the Mockfile. You can also useswiftymocky initif you want a placeholder you can fill manually.Note 2: To evaluate your Mockfile setup, as well as other things, run
swiftmocky doctor.Note 3: You can use
swiftymocky autoimportto prefilltestableandimportin your configurations.
View on GitHub
Mockfile Reference