Mockingbird

0.20.0

A Swifty mocking framework for Swift and Objective-C.
typealiased/mockingbird

What's New

0.20.0: Eagle Eye

2022-01-29T01:50:40Z

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

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.

Description

  • Swift Tools 5.2.0
View More Packages from this Author

Dependencies

  • None
Last updated: Sun Dec 15 2024 10:41:29 GMT-1000 (Hawaii-Aleutian Standard Time)