覆盖isReachable不适用于模拟

时间:2019-03-26 15:47:25

标签: swift alamofire

我想测试我的代码和行为。在这种情况下,我将覆盖Alamofire的NetworkReachabilityManager并打开var isReachable。在我的测试案例中,将调用NetworkReachabilityManager的isReachable方法,而不是MockNetworkReachabilityManager的方法。

DECLARE @table table (firstSix varchar(255))

WHILE(CAST(@min AS int) <= CAST(@max AS int))
BEGIN
     --here I will need to write a logic that concatenates the string. 
     INSERT INTO @table (firstSix)
         SELECT concat(@firstSix, right(concat('0', @min), 2))

     SET @min = @min + 1
END

SELECT firstSix
FROM @table;

1 个答案:

答案 0 :(得分:0)

最好的解决方案是,如果您使用协议并覆盖isReachable方法。然后我可以写一个`MockNetworkReachabilityManager``

protocol CustomNetworkReachability {
  var isReachable: Bool { get }
}

extension NetworkReachabilityManager: CustomNetworkReachability {}

class MockNetworkReachabilityManager: CustomNetworkReachability {
  var isReachable: Bool {
    return false
  }
}