Comments (4)
Hi, sorry again for the slow reply - I'm very busy with other projects at the moment.
You're right, it could be a toggled setting. I'm happy to do this when I find time but it would be great to see some support for this feature. Everybody reading this, please respond with a
from swiftmockgeneratorforxcode.
@seanhenry Do you know if this is the default behaviour ?
from swiftmockgeneratorforxcode.
Hi @gonzaloalu
Thanks for raising this issue and sorry for the late reply.
What you've described is expected behaviour. The way it works is that it will try to make the simplest unique name for each item. So in your case, you started with a method which was not overloaded so the simplest name invokedSet
was used. When you added the next method, it is now overloaded and the simpler method gets the simpler name and the more complex method gets the more verbose name.
Unfortunately the generator can't really know about the history of the generated mocks so it can't tell which was created first. And even if it could, in some cases, it would be impossible to avoid changing the generated name for the original method. For example:
protocol P {
func doSomething(param1: Int, param2: Int)
}
would generate:
...
var invokedDoSomething = false
...
then adding a new method to the protocol:
protocol P {
func doSomething(param1: Int, param2: Int)
func doSomething()
}
wouldn't be able to keep invokedDoSomething
for func doSomething(param1: Int, param2: Int)
because it wouldn't be able to generate a unique name for func doSomething()
.
I hear where you're coming from with using the full signature for the generated names but I think generating verbose names when it's not required would take away from the readability of your tests in most cases. Also, they would have to be more verbose than you're suggesting because you can have methods which have identical parameter labels but different types. So in your example the mock would become:
...
var invokedSetParam1IntParam2Int = false
...
I do recognise that the current strategy isn't perfect and re-generating that test double would likely have caused your tests to fail but this strategy was a conscious decision to maintain the readability of your tests with an unfortunate compromise of causing the generated names to change if adding an overloaded method.
What do you think?
from swiftmockgeneratorforxcode.
Hello @seanhenry, first of all thanks for your response and explanation, and sorry for the late response on our part.
I agree with you on the part that if we want to support same method signatures but different parameter types, It will be too verbose. ( I don't know another solution for this) But I think that this is not very common scenario. Also, the plugin doesn't support that today either.
Despite beign too verbose, I think that the plugin should build the method name with all its parameters. As I told you, we want to be in compliance with the Swift API Design Guidelines, and we found that in a lot of cases it's difficult to understand what method we are calling from the test due to lack of information. Let me give you an example that complies with this reference https://swift.org/documentation/api-design-guidelines/#argument-labels:
protocol MyLocationProtocol {
func set(latitude: Double, longitude: Double)
}
class MyLocationProtocolMock {
var invokedSet = false
var invokedSetCount = 0
var invokedSetParameters: (latitude: Double, longitude: Double)?
var invokedSetParametersList = [(latitude: Double, longitude: Double)]()
func set(latitude: Double, longitude: Double) {
invokedSet = true
invokedSetCount += 1
invokedSetParameters = (latitude, longitude)
invokedSetParametersList.append((latitude, longitude))
}
}
As you can see invokedSet
doesn't give you too much information about what you are calling.
We think that having the tool be more accurate when creating the mocks for every method would be more helpful than trying to have them simplified
invokedSet
is easy to read but doesn't give you any tip about what you are setting.
invokedSetLatitudeLongitute
is more verbose, but it's self explainatory.
Maybe this could be toggled in a setting? What do you think?
from swiftmockgeneratorforxcode.
Related Issues (20)
- Installation? HOT 1
- Using this with Objective C HOT 1
- Typo in permission error message
- Generated code does not follow the enclosing class access control HOT 1
- Extension doesn't work on Big Sur HOT 16
- ObjectToTest ???? HOT 2
- Can't find Mock Generator on Big Sur HOT 1
- import AST errors HOT 2
- Stubs are not generated when the member variable end in a '$'
- Optional properties have a force-unwrapped stub
- Installation via Homebrew
- Stopped working under Big Sur and Xcode 12.4 HOT 1
- Extensions not supported HOT 1
- Indentation follows Xcode ctrl-i
- Naming Conventions
- Generate async mocks HOT 6
- Cannot compile because of missing private framework `SwiftToolkit`
- Optional function parameter break generator
- Handle generic completion handlers in mocked function
- Can I enter it in the function?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from swiftmockgeneratorforxcode.