Swift too smart? Checking an objects type when testing with XCTest
To get around Swift being too smart, cast the item you are testing to type Any
and then test it. For instance, if you want to assert that the function fred()
returns an Int
func fred() -> Int {
return 3
}
assert((fred() as Any) is Int)
Try this in a Playground, and then change the return type to Float
and the assert will fire.
Just use is operator:
XCTAssertTrue(viewController is HomeViewController)