Fortunately there is no shortage of quality testing frameworks for iOS. I decided to focus my efforts on 3 of the available frameworks:
OCUnit
Based on the SenTest framework, OCUnit is a traditional xUnit style unit testing tool that comes bundled with the iOS SDK.Kiwi
An RSpec style testing tool with an extensible expectation syntax and built-in mocking tools for Behavior-Driven Development (BDD).KIF
A fully automated functional testing tool that simulates user interactions by leveraging accessibility attributes provided by the OS.Three the Hard Way (HelloTDDiOS)
Based on Your first iOS App tutorial on Apple Developer, Three the Hard Way allows you to enter a name via text input, click a button, and view the resulting greeting.
Development of the app was 100% test-driven using OCUnit. Below is an example of tests written to exercise the button callback in the view controller.
And the production code that was written to satisfy these tests. Notice how the tests use an instance of MockHelloTDDViewControllerDelegate to test the view controller in isolation rather than GreetingFactory (the actual delegate used in production).
And here are the same tests rewritten using Kiwi.
Finally, here is the end-to-end integration test using KIF that tests the button through a scripted UI interaction.
In order for KIF to locate the UI elements, we must set the accessibility labels in (void)viewDidLoad.
Fork the full project at https://github.com/ecgreb/Three-the-Hard-Way. Feedback is welcome.
I'd also recommend checking out specta.
ReplyDeletehttps://github.com/specta/specta