ios - Swift unit tests mock class static method -
i have static method in class
class { static func mystaticmethod() -> b { return b() } } class b { func gettitle() -> string { // functionality here } }
in class method want test use like:
func someboolfunc() -> bool { var b = a.mystaticmethod() if (b.gettitle() = “hello”) { return true } return false }
how write mock class this... tried:
class mocka: { var mytitle:string // seems incorrect, because didn't override static function func mystaticmethod() -> mockb { var b = mockb() b.title = mytitle return b } } class mockb: b { var mytitle:string func gettitle() -> string { return mytitle } }
and in tests wanted use like:
func testexample() { = mocka mocka.title = "my title" // , func should use mocka instead of someboolfunc() }
but of course in theory :(
maybe way?
protocol aproto { static func mystaticmethod() -> bproto } class a: aproto { static func mystaticmethod() -> bproto { return b() } } class mocka: aproto { static func mystaticmethod() -> bproto { return mockb() } } protocol bproto { func gettitle() -> string } class b: bproto { func gettitle() -> string { return "hello" } } class mockb: bproto { func gettitle() -> string { return "bye bye" } } func someboolfunc(_ aproto: aproto.type = a.self) -> bool { var b = aproto.mystaticmethod() if (b.gettitle() == "hello") { return true } return false } print(someboolfunc()) print(someboolfunc(mocka.self))
Comments
Post a Comment