Skip to content

Commit 1ba5988

Browse files
author
Sean Henry
committed
Adds README
1 parent 64af062 commit 1ba5988

File tree

3 files changed

+105
-0
lines changed

3 files changed

+105
-0
lines changed

MockGenerator.xcodeproj/project.pbxproj

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,7 @@
337337
35CDF1982CF619E9EB7EB843 /* StructureBuilderTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StructureBuilderTests.swift; sourceTree = "<group>"; };
338338
35CDF1DF23DA287BB89C98CE /* Element.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Element.swift; sourceTree = "<group>"; };
339339
35CDF23686B80D1A8FF37150 /* FormatUtil.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FormatUtil.swift; sourceTree = "<group>"; };
340+
35CDF32023D75565E3CBD23A /* XcodeMockGenerator.gif */ = {isa = PBXFileReference; lastKnownFileType = image.gif; path = XcodeMockGenerator.gif; sourceTree = "<group>"; };
340341
35CDF33961A5167417B7B98C /* ElementVisitor.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ElementVisitor.swift; sourceTree = "<group>"; };
341342
35CDF41BB007A5C1F4180748 /* PreferencesView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PreferencesView.swift; sourceTree = "<group>"; };
342343
35CDF4695C73C787CC3952DB /* SourceFileFinder.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SourceFileFinder.swift; sourceTree = "<group>"; };
@@ -544,6 +545,7 @@
544545
14CA2D6A1F40008F00900937 /* Frameworks */,
545546
14CA2D541F40007000900937 /* Products */,
546547
35CDFCBA18471CBB83E38C32 /* scripts */,
548+
35CDF720F8CE28402647AF36 /* readme */,
547549
);
548550
sourceTree = "<group>";
549551
};
@@ -648,6 +650,14 @@
648650
path = visitor;
649651
sourceTree = "<group>";
650652
};
653+
35CDF720F8CE28402647AF36 /* readme */ = {
654+
isa = PBXGroup;
655+
children = (
656+
35CDF32023D75565E3CBD23A /* XcodeMockGenerator.gif */,
657+
);
658+
path = readme;
659+
sourceTree = "<group>";
660+
};
651661
35CDF740D0A5864B2D1DBF81 /* structure */ = {
652662
isa = PBXGroup;
653663
children = (

README.md

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# Swift Mock Generator Xcode Source Editor Extension
2+
3+
An Xcode extension (plugin) to generate mock classes automatically.
4+
5+
![Xcode mock generator](readme/XcodeMockGenerator.gif)
6+
7+
[Looking for the AppCode version?](https://github.com/seanhenry/MockGenerator)
8+
9+
**IMPORTANT:**
10+
- This plugin is in development and only supports a fraction of the features offered in the [AppCode plugin](https://github.com/seanhenry/MockGenerator).
11+
- Only tested with Xcode 8.3.2 but will support Xcode 9 soon.
12+
13+
## Install Swift Mock Generator Xcode Source Editor Extension
14+
15+
- Download the latest release [here](https://github.com/seanhenry/SwiftMockGeneratorForXcode/releases)
16+
- Copy the app to the `Applications` folder.
17+
- Open the app
18+
- Select the path to your project ([Why do I have to do this?](##why-do-i-have-to-set-a-path-to-my-project?))
19+
- Open Xcode
20+
21+
## How to create a new Swift mock
22+
23+
- Create an empty mock class conforming to a protocol.
24+
25+
Example:
26+
```
27+
class MyMock: MyProtocol {
28+
}
29+
```
30+
- Place the cursor inside the class declaration.
31+
- Click `Editor -> Mock Generator -> Generate Mock`.
32+
33+
## How to recreate a Swift mock
34+
35+
If you change the underlying protocol its mock will need to be regenerated.
36+
37+
To regenerate the mock, simply follow the steps above.
38+
39+
## Recommended: assign a shortcut
40+
41+
- Select preferences `⌘,` in Xcode.
42+
- Choose 'Key Bindings'.
43+
- Search for 'Mock Generator'.
44+
- Choose your preferred shortcut. I prefer `⌃⌥⌘M`.
45+
46+
## Recommended: use source control
47+
48+
The mock generator will replace anything that is currently in your mock class with the generated mock.
49+
50+
Undo is supported for Xcode plugins but you're safer to use source control in the event of unexpectedly generating a mock.
51+
52+
## Features
53+
54+
| Feature | Xcode | AppCode
55+
|---|---|---|
56+
| Captures invocation status of methods.|||
57+
| Captures invocation status of properties.|||
58+
| Captures invoked method parameters.|||
59+
| Stubs values for your mocks to return.|||
60+
| Stubs a default value for return values where possible.|||
61+
| Automatically calls closure parameters with stubbed values.|||
62+
| Supports mocks conforming to one or many protocols.|||
63+
| Handles overloaded method declarations.|||
64+
| Regenerate your mock in one action.|||
65+
| Supports associated types.|||
66+
| Supports parameter type-annotation attributes and inout.|||
67+
| Respects public and open mocks and makes queries publicly available.|||
68+
| Records multiple invocations of methods.|||
69+
| Records multiple invocations of method parameters.|||
70+
| Generate mocks from protocols in 3rd party frameworks.|||
71+
| Generate mocks from classes|||
72+
73+
## Feature requests
74+
75+
As shown above, the AppCode plugin is much more feature-rich. If there is a feature you need, check for an existing GitHub issue and make a comment or, if no issue exists, raise a new issue.
76+
77+
## Disable or remove the plugin
78+
79+
To disable:
80+
81+
Go to `System Preferences -> Extensions` and deselect the extension under `Xcode Source Editor`.
82+
83+
To remove:
84+
85+
Delete the app.
86+
87+
## Nomenclature
88+
89+
Despite being called a Mock Generator, this plugin actually generates something closer to a spy and stub. The word 'mock', whilst not technically correct, has been used because test doubles such as spies, mocks, and stubs have become colloquially known as mocks.
90+
91+
## Why do I have to set a path to my project?
92+
93+
The plugin uses SourceKit which needs a list of your Swift files to index.
94+
95+
You have to set the path to your code because there is no way to derive it from an Xcode extension.

readme/XcodeMockGenerator.gif

1.26 MB
Loading

0 commit comments

Comments
 (0)