iOS test Tool Research (1)-----------xctest Unit Test

Source: Internet
Author: User

After the software testing this course began to practice software testing methods, because the individual more emphasis on iOS development, so began to the iOS platform software Testing technology research

Apple integrated the new Unit testing tool, Xctest, in its own development tool Xcode in 2014.

First, to talk about what is unit testing

Unit testing refers to the process of testing the most basic elements of a program, such as a function, a menu, an interface, and the smallest executable unit.

Individual understanding of unit testing can ensure the robustness of the program, but also to develop defensive programming good habits

Second, xctest framework

1. Overall look how to use it

The usage is very simple, it is plain to realize that a xctest subclass can be

Example: Creating a First_test test class

@interface First_test:xctest

There are two functions that must be implemented

 -(void) setUp;

-(void) TearDown;

Is the two callback function that represents the start of the test and the end of the test, where the variable is initialized

2. First Test

Import a class target to be tested in the FIRST_TEST.M test class header

#import "Target.h"

And a new test method in FIRST_TEST.M-(void) testexample{...}, the test method begins with the

  

Then you write a small piece of code in this method to test.

Here we deliberately construct a wrong method, because Carid is not equal to 100, so throw an error here

  

We see Xctassertequal (...) is an assertion statement, which the compiler judges here.

Xctest Framework is composed of various assertions, which facilitates the judgment of the results.

iOS test Tool Research (1)-----------xctest Unit Test

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.