Comments (2)
Hi @BergQuester
Thanks for raising this issue. Static mocks are a little more complicated because it will be very easy to accidentally keep state between tests. And I think, no matter what we do, static methods cannot be mocked when doing parallel testing.
That said, I can see how the missing support for static methods is irritating since they won't compile and require code to be added manually after each generation. So perhaps with documentation of their restrictions we can add this feature.
I think the main challenge is to easily reset mock state between tests so I've come up with the following:
protocol MyProtocol {
static func a()
}
class MyProtocolMock: MyProtocol {
class Static {
var invokedA = false
var invokedACount = 0
}
static var `static` = Static()
static func a() {
MyProtocolMock.static.invokedA = true
MyProtocolMock.static.invokedACount += 1
}
}
class MyClass {
static func a() {} // cannot be overridden
class func b() {}
}
class MyClassMock: MyClass {
class Static {
var invokedB = false
var invokedBCount = 0
}
static var `static` = Static()
override class func b() {
MyClassMock.static.invokedB = true
MyClassMock.static.invokedBCount += 1
}
}
class MyTest: XCTestCase {
var mock: MyProtocolMock!
override func setUp() {
super.setUp()
mock = MyProtocolMock()
MyProtocolMock.static = .init()
}
}
What do you think?
from swiftmockgeneratorforxcode.
Closed due to inactivity
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.