How to setup KIF for UI testing?

How to setup KIF for UI testing?

tudip-logo

Tudip

13 June 2019

What is KIF?

KIF stands for Keep It Functional. It is an iOS integration test framework which is used for UI testing of iOS mobile apps.

Note: Though KIF used for UI testing you have to add it to your Unit Test Target. KIF allows you to test your UI from your unit tests.

Advantages of using KIF is , it is easy to configure and use

“KIF integrates directly into your Xcode project so there is no need to install additional packages or run any web server.”

Let’s see how to setup KIF to your xcode project ?

  1. Adding the tests target:
    If you have not added the test target then go to your xcode and click “Add Target” in xcode editor. Select iOS Unit Testing Bundle. Give the test target name like “MyAppTests” or anything that indicates the intent of your tests process.Adding the tests target to your Podfile

    target '' do
    ...
    end
    target 'MyAppTests' do
    use_frameworks!
    pod 'KIF', :configurations => ['Debug']
    end

    Run `pod install` in the terminal.

  2. Creating the KIF helper for swift:
    Create “KIF+Extensions.swift” in your project’s tests target.

    import KIF
    extension XCTestCase {
    func tester(file : String = #file, _ line : Int = #line) -> KIFUITestActor {
    return KIFUITestActor(inFile: file, atLine: line, delegate: self)
    }
    func system(file : String = #file, _ line : Int = #line) -> KIFSystemTestActor {
    return KIFSystemTestActor(inFile: file, atLine: line, delegate: self)
    }
    }
    extension KIFTestActor {
    func tester(file : String = #file, _ line : Int = #line) -> KIFUITestActor {
    return KIFUITestActor(inFile: file, atLine: line, delegate: self)
    }
    func system(file : String = #file, _ line : Int = #line) -> KIFSystemTestActor {
    return KIFSystemTestActor(inFile: file, atLine: line, delegate: self)
    }
    }
  3. Create the Bridging Header:
    Click on your tests target > New File > a window will appear in which you have to select the “Objective-C File”.
    You’ll get a pop-up :
    “ Would you like to configure an Objective-C bridging header? ”
    Choose “Create Bridging Header”. To complete the process delete the .m file from your tests target as, we don’t need it.
    Your test bundle’s bridging header will need to #import <KIF/KIF.h>, since KIF is a static library and not a header.
  4. Create test cases:
    Now you are ready to create the test cases.

References

  1.  https://www.appcoda.com/automated-ui-test/
  2.  https://github.com/kif-framework/KIF

search
Blog Categories
Request a quote