【发布时间】:2018-01-08 10:56:05
【问题描述】:
我在尝试用 swift 编写一些 UT 时遇到问题
我有一个扩展名为“做事”的协议:
protocol MyProtocol: class
{
var myVar: SomeClass { get }
func doStuff(identifier: String) -> Bool
}
extension MyProtocol
{
func doStuff(identifier: String) -> Bool {
return true
}
}
然后是一个实现我的协议的类
final class MyClass: MyProtocol {
}
这个类有一个扩展,它实现了另一个协议,它有一个我应该测试的方法
public protocol MyOtherProtocol: class {
func methodToTest() -> Bool
}
extension MyClass: MyOtherProtocol {
public func methodToTest() {
if doStuff() {
return doSomething()
}
}
}
这种设置有没有办法模拟 doStuff 方法?
【问题讨论】:
标签: swift unit-testing swift-protocols