Step 1 – Create new project (Single view application)

Include Unit Tests and UI tests so that project will automatically create required files otherwise we need to create it by own.

Screen Shot 2017-08-09 at 6.30.17 PM.png

Step 2 : Create pod

  1. Open terminal
  2. Go to project folder by command cd (your project path — you can get this by just dragging project folder to terminal)
  3. write Command pod init
  4. In project folder new pod file created.
  5. open pod file and write Alamofire pod
  6. pod 'Kiwi'

    POD file should look like this.

Note – add pod  ‘Kiwi’ only in unit test target as we are using this for unit testing.

Screen Shot 2017-08-09 at 6.34.19 PM6. Then install pods into your project by typing in terminal: pod install

Screen Shot 2017-08-09 at 6.37.00 PM.png

7. Now close your Xcode project and open .xcworkspace Xcode project file and start coding

In Project – 

In file navigator find folder name KiwiTestTests. Then in same folder find file KiwiTestTests.m which is your unit test file created by default for you. You can run this test from test navigator or from file itself as shown below (but we are not going to use this file for Kiwi testing)

Screen Shot 2017-08-09 at 6.46.58 PM.png

Write First Kiwi Test

To demonstrate how simple Kiwi syntax is, we will be writing a spec to make sure the sum (+) method is working properly.

To create a new test file go to File -> New -> File (or CMD-n). Select the option “Objective-C test case class” from the iOS – Cocoa Touch menu and click Next.

Screen Shot 2017-08-09 at 7.12.37 PM.pngProvide a name for the new file. For our app example we will call it “MathSpec”.

Screen Shot 2017-08-09 at 7.12.57 PM.png

Select the subclass type, we will be using “XCTestCase”, click next and choose were the file will be stored. Make sure the checkbox option “KiwiTest” target is checked and click to create the file.

Screen Shot 2017-08-09 at 7.13.12 PM.pngXcode will open the generated file automatically.

This file contains a default template based on the XCTestCase. Since we are not using any of this, you can remove all the content and use the following code:

Before writing Specs import Kiwi

Screen Shot 2017-08-09 at 7.16.15 PM.png

Now use CMD+u to run your spec and Xcode will display the results for your test.

Screen Shot 2017-08-09 at 7.20.06 PM.png

You can try to get test fail by writing 40 +2 sum other than 42.


Hope you find this blog useful. Please feel free to contact with me in case you have any query, suggestions.  You can comment, like and follow posts. Please take a few seconds and share it with your friends! 

You can request any topic related to Swift and iOS development.