ios_30_ Unit Test

Source: Internet
Author: User

Unit Test considerations:

1. The test class must be a subclass of xctestcase that can be automatically generated using the project, or you can create a new test class on your own to test a specific the class being tested


2. Import the class being tested . such as Mathtool

3. New test method, must start with Test, object method, and no return value, no parameters

4. In the test method, according to the specific situation, using Xctassert ... Method to assert the method to be tested inside the class being tested

5. No need to run the program, directly click on the left of the method of the circular button, you can execute the test method




Create a new test method



Click the triangle button on the left side of the test method to start the test


The test result is red because the tool class has not yet implemented the method



Click the triangle button on the left of the method again to perform the test


After correcting the method of the tool class, execute the test again, the result is green



To create a custom test class





Click the test method, the left side of the Execute button to start the test


Red indicates a test error


Green indicates correct test



  _0_____tests.m//  30_ Unit test tests////  Created by Beyond on 14-9-5.//  Copyright (c) 2014 Com.beyond. All rights reserved.//  as long as it inherits from Xctestcase, this class has the function of unit test #import <xctest/xctest.h>//1. First import the class to test #import " MathTool.h "@interface _0_____tests:xctestcase@end@implementation _0_____tests-(void) setup{    [Super setUp];    Before each test method in this class starts, the Setup method}-(void) teardown{    //will run the TearDown method before the end of each test method in this class            [Super TearDown];} Test method, must start with textxxx, and is an object method, and no return value, and no parameter-(void) testsum{    xctassertequal ([Mathtool sumwitha:6 andb:7], @ "summation method is wrong ~");} -(void) testexample{    xctfail (@ "No implementation for \"%s\ "", __pretty_function__);} @end



  girltest.m//  30_ Unit test////  Created by Beyond on 14-9-5.//  Copyright (c) 2014 Com.beyond. All Rights reserved.//  custom Unit test class, as long as inherit from Xctestcase, this class has the function of unit test #import <xctest/xctest.h>//Specialized test girlfactory Inside the method #import "GirlFactory.h" @interface girltest:xctestcase@end@implementation girltest-(void) setup{    [Super SETUP];    Before each test method in this class starts, the Setup method        }-(void) teardown{    //will run the TearDown method before the end of each test method in this class            [Super TearDown];} Test method, must start with textxxx, and is an object method, and no return value, and no parameter-(void) testgirlfactory{    xctassertnotnil ([girlfactory girl], @ "Girlfriend factory error, Unable to produce a girlfriend ~ ");} -(void) testexample{    xctfail (@ "No implementation for \"%s\ "", __pretty_function__);} @end





ios_30_ 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.