Stubber 1.5.3

Stubber 1.5.3

测试已测试
语言语言 SwiftSwift
许可 MIT
发布最新发布2020年6月
SPM支持SPM

Suyeol Jeon维护。



Stubber 1.5.3

  • Suyeol Jeon

Stubber

Swift CocoaPods Build Status Codecov

Swift的最小方法存根。

概览

import Stubber

final class StubUserService: UserServiceProtocol {
  func follow(userID: Int) -> String {
    return Stubber.invoke(follow, args: userID)
  }

  func edit(userID: Int, name: String) -> Bool {
    return Stubber.invoke(edit, args: (userID, name))
  }
}

func testMethodCall() {
  // given 
  let userService = StubUserService()
  Stubber.register(userService.follow) { userID in "stub-\(userID)" } // stub
  
  // when
  userService.follow(userID: 123) // call
  
  // then
  XCTAssertEqual(Stubber.executions(userService.follow).count, 1)
  XCTAssertEqual(Stubber.executions(userService.follow)[0].arguments, 123)
  XCTAssertEqual(Stubber.executions(userService.follow)[0].result, "stub-123")
}

逃逸参数

当函数包含一个逃逸参数时,在参数上使用escaping()

 func request(path: String, completion: @escaping (Result) -> Void) {
-  Stubber.invoke(request, args: (path, completion))
+  Stubber.invoke(request, args: escaping(path, completion))
 }

安装

pod 'Stubber'

许可

Stubber遵循MIT许可证。有关更多信息,请参阅LICENSE