Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Unit testing of swift project - User experience (UX)

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 536
    Comment on it

    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 :-

     

    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)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: