Casting in XCTest Methods
The XCTest framework added the super helpful function
XCTUnwrap
back in Xcode 11. At the time I added a similar helper to my various projects to help smooth over the many cases where casting is required. The idea is to have a similar call site toXCTUnwrap
but for use in situations where you want to verify you have the right type or fail.
His example also demonstrates using the new record(_ issue: XCTIssue)
method, which lets you provide more information than just failing with a string description.
I added casting to my tests around the time I added unwrapping and find it very helpful. And you can often use type inference to avoid having to pass in the type.
Previously: