Hi All,
In iOS , We have two type of testing one is UI testing (User interface) and UX testing (User experience). In this tutorial we will learn UX testing of an ios app.
User experience (UX) is the internal experience that a person has as they interact with every aspect of a application.
You can add unit testing to existing project or create a new one with unit testing enabled. We will work on new project as followed.
1) Create a new project with unit testing enabled :-
![](https://lh3.googleusercontent.com/-rp0w8snFktA/WMedbMy6kAI/AAAAAAAAJaM/PtpzmrZF6SQaPODodniaa_ws0DC0_caBgCJoC/w530-h363-p/Screen%2BShot%2B2017-03-14%2Bat%2B1.03.33%2BPM.png)
2) To understand we will create a function in view controller class :-
open func subtractionOfTwoNumbers(a:Int,b:Int) -> Int {
print("a+b+=\(a+b)")
return a-b
}
We make this method open so that we can access this method to test the functionality.
3) Now go to unit test class and you can see testExample method , write the code to test test particular method from your project. In setUp method , create instance of a viewcontroller like :-
var vc:ViewController?
override func setUp() {
super.setUp()
// Put setup code here. This method is called before the invocation of each test method in the class.
let storyboard = UIStoryboard(name: "Main", bundle: Bundle.main)
vc = storyboard.instantiateInitialViewController() as? ViewController
}
and now we write code to test viewcontroller method as :-
func testExample() {
// This is an example of a functional test case.
// Use XCTAssert and related functions to verify your tests produce the correct results.
let x = vc?.subtractionOfTwoNumbers(a: 10,b: 10)
XCTAssert(x == 0, "failedssdsasdasdasdasd")
}
Now run the method and check did your method pass the test or not , if green check comes after running the method then method is passed in unit testing or if cross sign comes then it failed. You can test as many method as you want of your project.
0 Comment(s)