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.
Step 2 : Create pod
- Open terminal
- Go to project folder by command cd (your project path — you can get this by just dragging project folder to terminal)
- write Command pod init
- In project folder new pod file created.
- open pod file and write Alamofire pod
POD file should look like this.
Note – add pod ‘Kiwi’ only in unit test target as we are using this for unit testing.
6. Then install pods into your project by typing in terminal: pod install
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)
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.
Provide a name for the new file. For our app example we will call it “MathSpec”.
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.
Xcode 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
Now use CMD+u to run your spec and Xcode will display the results for your test.
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.
Donate any small amount you think for this knowledge to grow this forum.
To Donate – paypal.me/SandeshSardar