Swiftpack.co - birdrides/mockingbird as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by birdrides.
birdrides/mockingbird 0.20.0
A Swifty mocking framework for Swift and Objective-C.
⭐️ 495
🕓 28 weeks ago
iOS macOS watchOS tvOS
.package(url: "https://github.com/birdrides/mockingbird.git", from: "0.20.0")

Mockingbird - Swift Mocking Framework

Mockingbird

Package managers MIT licensed #mockingbird Slack channel

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.

Documentation

Visit MockingbirdSwift.com for quick start guides, walkthroughs, and API reference articles.

Examples

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()

Contributing

Please read the contributing guide to learn about reporting bugs, developing features, and submitting code changes.

License

Mockingbird is MIT licensed. By contributing to Mockingbird, you agree that your contributions will be licensed under its MIT license.

GitHub

link
Stars: 495
Last commit: 3 weeks ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Related Packages

Release Notes

0.20.0: Eagle Eye
28 weeks ago

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

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics