You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I deemed the compound module concept as useless for now.
If we want to import protocol with an identical name from different targets, we should work on prefixing them with their target name in the generated mocks.
Copy file name to clipboardExpand all lines: README.md
+23-37Lines changed: 23 additions & 37 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -133,63 +133,49 @@ target = "Cuckoonator"
133
133
134
134
#### For CuckooPluginModular
135
135
136
-
When using `CuckooPluginModular`, the plugin automatically detects source modules from your test target's dependencies and generates a dedicated mock file for each one (`GeneratedMocks_<ModuleName>.swift`). It supports compound module names (`TARGET/MODULE`) in `Cuckoofile.toml` so that different test targets can customize mock generation for shared dependencies.
136
+
`CuckooPluginSingleFile` puts all mocks into a single `GeneratedMocks.swift` file in derived data. In a Swift Package with multiple targets this is problematic because each test target compiles independently and may not have visibility into types from unrelated modules. Use `CuckooPluginModular` instead: it inspects your test target's dependencies and runs the generator once per dependency module, producing a separate `GeneratedMocks_<ModuleName>.swift` for each.
137
+
138
+
A `Cuckoofile.toml` entry is required for each module you want to generate mocks for. The plugin looks up the test target's own name (e.g. `[modules.TargetATests]`), letting you specify which source files to mock and which imports to add. Modules without a matching entry produce an empty file and no mocks.
137
139
138
140
**Example `Cuckoofile.toml` for modular projects:**
139
141
140
142
```toml
141
-
# CoreModule mocks
142
-
[modules.CoreModuleTests]
143
-
imports = ["Foundation"]
144
-
testableImports = ["CoreModule"]
145
-
sources = [
146
-
"Sources/CoreModule/ServiceProtocol.swift"
147
-
]
148
-
149
-
# NetworkAPI module mocks
150
-
[modules.FirstNetworkAPITests]
143
+
# TargetA mocks
144
+
[modules.TargetATests]
151
145
imports = ["Foundation"]
152
-
testableImports = ["FirstNetworkAPI"]
146
+
testableImports = ["TargetA"] #ProtocolA is internal to TargetA
-**Multiple modules define protocols/types with identical names** (e.g., both `ModuleA` and `ModuleB` have a `ServiceProtocol`)
190
-
- Different test targets need different subsets of mocks from the same module
191
-
- You want to organize and namespace mocks by test target for clarity
192
-
193
179
### 3. Usage
194
180
Usage of Cuckoo is similar to [Mockito](http://mockito.org/) and [Hamcrest](http://hamcrest.org/). However, there are some differences and limitations caused by generating the mocks and Swift language itself. List of all the supported features can be found below. You can find complete examples in [tests](Tests).
0 commit comments