IOS unit test sentest

Source: Internet
Author: User

Environment: xcode 4.2

1. Create a target for the unit test

Select a project and click Add target to add the cocoa touch unit testing bundle type target under iOS-Other (figure 1 ). (According to some information on the Internet, the target suffix must be tests, but the actual test is irrelevant to the name, probably because of the xcode version.) 2.

Figure 1

Figure 2

In this case, there will be an additional testfuc folder in the project directory. The folder structure is 3. The testfuc class is an instance of the sentestcase test case class:

Figure 3

2. Add sentestingkit. Framework

Select the target for the test, testfuc in this project. Check link binary with libraries under the build phases tab. You will find that the project lacks reference to the sentestingkit. Framework library and add it.

3. Run testfuc Test

Select testfuc in scheme, and test must be selected during generation. If run is selected,"The scheme 'testfuc' is not configured for running.

After running successfully, an output error is found. The error message is as follows:

Testfuc. M: 29: Error:-[testfuc testexample]: unit tests are not implemented yet in testfuc

Test Case '-[testfuc testexample]' failed (0.000 seconds ).

Open testfuc. M and you will find that a test function testexample is added to the implementation file of the testfuc class by default, and an execution failure prompt is added, as shown below:

-(Void) testexample {

Stfail (@ "unit tests are not implemented yet in testfuc ");

}

The test preparation is complete. You can add a test function to the class instance of the test case. The name of the test function cannot be customized, it must be prefixed with test. You can add multiple test cases to the test folder for testing.

4. Add a test object class for testing

After completing step 3, you can start to test the method of a specific class in the project. In addition to adding a reference to the class in the corresponding test case, you must firstAdd this class reference to the target of the test (very 2 due to this problem for a long time)In this project, testfuc is used. To add a reference, click test target (testfuc), select panel build phases, open compile sources, and drag the. m implementation file of the project to test the class into compile sources. Otherwise, the following error occurs:

Undefined symbols for architecture i386:

"_ Objc_class _ $ _ test class name", referenced from:

Objc-class-ref in testfuc. o

Ld: symbol (s) not found for architecture i386

If the test class has a NIB file, you need to drag the NIB file into build phases -- Copy bundle resources.

PS: test preliminary study. if the error is found or you need to add a comment, please remind me ~~ At present, I feel that I have spent a lot of effort to test several static functions and interface attributes .. Directly perform single-step debugging in the project, which may be faster ..

 

 

Related Article

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.