XCTest Tutorial

XCTest: 
  1. 1. XCTest is an iOS native framework for unit testing UI testing of your project. XCTest mainly focuses on functional testing such as UI Elements testing and Some Static data.  
  1. 2. XCTest uses id's of elements use test appearance. Id's nothing but names of UI Elements appears on the application. 

What can Test? 
  1. 1. UI Elements of your application. 
  1. 2. Static data displayed in your application. 
  1. 3. The position of UI Elements. 
  1. 4. Web pages. 

What can't Test? 
  1. 1. Can't access other applications like external application (Safari, Gmail, Web application etc.,) 
  1. 2. Not possible to access two devices at a time. 
  1. 3. The required manual effort to check application behaviour in offline mode (Without internet) 
  1. 4. Not possible to check for spinner, ribbon messages. 
  1. 5. We can't test dynamic data in all scenarios. 

How to add XCTest to your applications? 
There are 2 ways we can add XCTest framework to your project. 
  1. 1. Add XCTest framework while creating the project. 
XCode -> New Project -> Single View App -> Give Project Name -> Tick UI Test or Unit Test. 



  1. 2. You can see XCTest added to project or not by clicking (-) button on right side of the toolbar. 



  1. 3. You can work with many swift files by creating new files (If you want to keep the separate file for different modules). 




  1. 4. Add subclass to file as "XCTestCase" 


  1. 5. After creating swift file import "XCTest" framework by giving, 
import XCTest 
  1. 6. Create a method to setUp application inside the class. 
  1. 7. Create tearDown method which will start execution with this method. 


  1. 8. Create your own functions based on requirement. 

Another way to add XCTest framework to your project is, 
  1. 1. Click on "-" button on the top left pane. 
  1. 2. At bottom of the project area, click on "+" icon and add new UI Tests or Unit tests. 



How to run individual function(method) or class? 
  1. 1. To run individual method, click on the icon displayed in the screenshot. 


2.To execute total functions at a time, 



How to generate the report? 
  1. 1. To generate the report, we have several ways to do based on requirement. 
  1. 2. One way of generating report through plist. After completing of execution, find path to Developer-> XCode-> Derived Data-> Project folder-> Logs-> Test -> .plist file(Select it based on execution completion time). 
  1. 3. Plist file contains all the info about test cases where you can get data and convert to report. 

Comments