-
Notifications
You must be signed in to change notification settings - Fork 21
[PM-25300] Add Sourcery usage on iOS architecture #631
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
43eb39e
397278d
a292135
e4938b5
9d8aaed
b312c12
e50d215
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -74,6 +74,7 @@ SDLC | |
| Serilog | ||
| signtool | ||
| signup | ||
| Sourcery | ||
| sqlcmd | ||
| struct | ||
| structs | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -453,6 +453,54 @@ This makes it convenient to switch between these files or open them side-by-side | |||||
| [ios version](https://github.com/bitwarden/ios/blob/main/.test-simulator-ios-version)), otherwise | ||||||
| tests may fail because of subtle differences between iOS versions. | ||||||
|
|
||||||
| ### Mock generation | ||||||
|
|
||||||
| We use [Sourcery](https://github.com/krzysztofzablocki/Sourcery) for automatic mock generation. | ||||||
|
|
||||||
| In order to automatically generate a mock from a protocol, just add a comment with | ||||||
| `// sourcery: AutoMockable` to such protocol, perform a build and the mock will be automatically | ||||||
| generated and added to the `AutoMockable.generated.swift` file. | ||||||
|
|
||||||
| For example: | ||||||
|
|
||||||
| ```swift | ||||||
| protocol FooProtocol { // sourcery: AutoMockable | ||||||
| func bar() -> Bool | ||||||
| } | ||||||
| ``` | ||||||
|
|
||||||
| :::info Manual generation | ||||||
|
|
||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| There are some cases where the automatically generated mock does not cover the mock scenario we want | ||||||
| or it cannot handle some closure types, especially in function parameters. In such cases prefer to | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. โ๏ธ Grammar: "function parameters" (noun adjunct) is more natural than "function's parameters" (possessive).
Suggested change
|
||||||
| create the mock manually and remove the protocol's `AutoMockable` comment. | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. โ๏ธ Grammar: Missing "to" before "create". Should be "prefer to create the mock manually".
Suggested change
|
||||||
|
|
||||||
| ::: | ||||||
|
|
||||||
| #### Custom annotations | ||||||
|
|
||||||
| Sourcery allows us to annotate different parts of our code to guide code generation. Custom | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ๐ญ Clarity: This sentence structure could be improved for readability. Suggested rewrite:
Suggested change
|
||||||
| annotations have been added in `AutoMockable.stencil` to handle special cases. | ||||||
|
|
||||||
| - **useSelectorName**: Method annotation used to indicate that the generated mocked properties need | ||||||
| to use the selector name instead of the short method name. This is especially useful when using | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. โ๏ธ Grammar: "parameter names" (noun adjunct, preferred) is more natural than "parameter's names" (possessive).
Suggested change
|
||||||
| function overloading where we need the mocked names to also have the parameter names to | ||||||
| differentiate between the different mocked functions. | ||||||
| - **mockReceivedInvocations**: Method annotation used to indicate that we want to generate the | ||||||
| mocked property to store an array of the received invocations of the parameters passed each time | ||||||
| the function is called. | ||||||
|
|
||||||
| For example: | ||||||
|
|
||||||
| ```swift | ||||||
| protocol FooProtocol { // sourcery: AutoMockable | ||||||
| func bar(fooParameter: String) -> Bool | ||||||
| func bar(anotherParameter: Int) -> Bool // sourcery: useSelectorName | ||||||
| func saveNumber(theNumber: Int) -> Bool // sourcery: mockReceivedInvocations | ||||||
| func annotateMultiple(fooParameter: String) // sourcery: useSelectorName, mockReceivedInvocations | ||||||
| } | ||||||
| ``` | ||||||
|
|
||||||
| ### Test plans | ||||||
|
|
||||||
| Test plans are organized in the `TestPlans` folder of the iOS repository. Each project has multiple | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.