One of the things I’m currently working on is getting back into my old Rails habit of testing my code. With KIF and XCTest frameworks, testing has become a lot simpler in iOS. However, as I started with KIF in my Swift app, I ran into an issue, which was luckily easy enough to resolve. But as I’ve been writing my tests in Swift, I’ve also found some new Swift-only patterns that I’ve been enjoying and wanted to share.

I’ll use my demo Seinfeld Quotes app as an example. I’m going to simply test the adding quotes functionality. Here is how the KIF test works:

While KIF is still under work for compatibility with Swift, I added an extension, as suggested by @bnickel in the Swift KIF Issue on Github, with a slight modification to keep the tester and system syntax a lot closer to the original:

Accessibility Labels

KIF uses Accessibility Labels to find views on each screen. Since Accessibility Labels can change easily (e.g. if the button title changes, for example), I like to keep the string versions of all my accessibility labels as constants.

However, with Swift, I found that it could be really nice to keep these together in enums in a private extension: