Mockingbird makes it easy to mock, stub, and verify objects in Swift unit tests. You can test both Swift and Objective-C without writing any boilerplate or modifying production code.
Visit MockingbirdSwift.com for quick start guides, walkthroughs, and API reference articles.
Automatically generating mocks.
$ mockingbird configure BirdTests -- --target Bird
Manually generating mocks.
$ mockingbird generate --testbundle BirdTests --target Bird --output Mocks.generated.swift
Using Mockingbird in tests.
// Mocking
let bird = mock(Bird.self)
// Stubbing
given(bird.canFly).willReturn(true)
// Verification
verify(bird.fly()).wasCalled()
Please read the contributing guide to learn about reporting bugs, developing features, and submitting code changes.
Mockingbird is MIT licensed. By contributing to Mockingbird, you agree that your contributions will be licensed under its MIT license.
link |
Stars: 495 |
Last commit: 3 weeks ago |
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
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()
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()
Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics