Targets
Framework
- Xcode 12.5+ / Swift 5.4+
- iOS 9.0+, macOS 10.10+, tvOS 9.0+, watchOS 7.4+
Generator
- macOS 10.15+
Migrating from 0.19
Mocking static members no longer requires referencing the staticMock
property when resetting mocks or clearing stubs/invocations.
// Old
reset(BirdMock.staticMock)
reset(type(of: mock(Bird.self)).staticMock)
// New
reset(BirdMock.self)
reset(type(of: mock(Bird.self))) // Preferred equivalent
New Features
Test async methods
You can now mock, stub, and verify async methods. Note that stubbing and verifying declarations requires the use of the await
keyword due to limitations with Swift’s overload resolution. Thanks to @ailtonvivaz for implementing this feature (#277).
protocol Bird {
func fetchMessage() async -> String
}
let bird = mock(Bird.self)
given(await bird.fetchMessage()).willReturn("Hello")
print(await bird.fetchMessage()) // Prints "Hello"
verify(await bird.fetchMessage()).wasCalled()
Verify initializers
This release adds the ability to verify how mocks are initialized in cases where the metatype is provided to the system under test. Thanks to @myihsan for implementing this feature (#280).
protocol Bird {
init(name: String)
}
func createBird(type: Bird.Type) -> Bird {
return type.init(name: "Ryan")
}
let bird = createBird(type(of: mock(Bird.self)))
verify(bird.initialize(name: "Ryan")).wasCalled()
Enhancements
- Improved the static mocking APIs and documentation (#287)
@andrewchang-bird - Fixed handling of read-only subscripts (#285)
@andrewchang-bird | @logicxd - Added the ability to mock sources in test bundles (#286)
@andrewchang-bird | Karl - Fixed cache invalidation when generating mocks for targets outside of the test target’s project context (#278)
@andrewchang-bird - Fixed handling of optional members in Objective-C protocols (#279)
@andrewchang-bird