Keep It Functional 2.0

Nearly 2 years ago I wrote the post “iPhone test automation using KIF (Keep It Functional)“. The fact that I am not working with KIF in one of my current projects, I missed the new KIF 2.0 release. The new version was released in september 2013 with a major rewrite of the framework.
KIF 2.0 is built on top of ocunit and is able to execute the tests sequentially as they appear in your code. In the old version the test execution based on steps and scenarios.

If you check the example on the KIF github page you will see the whole new structure of KIF. In the old version you had to create a KIFTestScenario object. Then you had to add several KIFTestSteps to that object to interact with your application. In the new version you have two main classes KIFTestCase and KIFUITestActor. The ocunit test runner is loading the test cases from KIFTestCase. Inside the tests the tester object is interacting with your application under test. The tester object offers several actions that can be used for testing. The most used ones are:

  • tap this view
  • enter text into this view
  • wait for this view

See a sample login test method with KIF 2.0

...
- (void)testLogin
{
    [tester enterText:@"testUser" intoViewWithAccessibilityLabel:@"Login User Name"];
    [tester enterText:@"testPassword" intoViewWithAccessibilityLabel:@"Login Password"];
    [tester tapViewWithAccessibilityLabel:@"Log In"];

    [tester waitForTappableViewWithAccessibilityLabel:@"Welcome to your account"];
}
...

Compared to the old version

...
- (id)scenarioLogin{
   KIFTestScenario *scenario = [KIFTestScenario  
      scenarioWithDescription:@"Login with credentials"];

   [scenario addStep:[KIFTestStep  
      stepToEnterText:@"testUser" intoViewWithAccessibilityLabel:@"Username"]];

   [scenario addStep:[KIFTestStep 
      stepToEnterText:@"testPassword" intoViewWithAccessibilityLabel:@"password"]];

   [scenario addStep:[KIFTestStep 
      stepToTapViewWithAccessibilityLabel:@"Log in"]];

   [scenario addStep:[KIFTestStep
      stepToWaitForViewWithAccessibilityLabel:LocalizedString (@"Welcome")]];

   return scenario;

}
...

Also the new version of KIF relies on accessibility labels, so be sure to provide a full accessible app. I really like the new version of KIF because it is much shorter and clearer.

Besides the new structure, KIF also offers some more functionality:

  • Use breakpoints between your test steps.
  • Test failures are shown in Xcode.
  • No need to create a duplicate target.
  • It is working with Xcode 5 command line tools, test navigator, and Bots.
  • And you can combine it BDD frameworks like Specta.

Have fun with new version of KIF!

Source: https://github.com/kif-framework/KIF