In-depth analysis of iPhone Project Unit Testing

Source: Internet
Author: User

In-depth analysisIPhoneMedium ProjectUnit TestIs the content to be introduced in this article, inXcodeAfter the iPhone SDK 3.0Unit TestFunction, developers can use unit tests to write more robust and correct code.

The SDK version used in this article is 3.2.3.XcodeProvides two typesUnit TestMethods: Logical testing and application testing. Logical testing is used to test independent functions without environment restrictions. In this case, logical testing does not require starting a simulator or a real machine, it is completed directly in the build phase. Application testing is used to detect yourIPhoneApplications, including interface operations.

Logic Test

Logical test procedure:

Add a new target to the iPhone project, select the iPhone OS-Cocoa Touch-Unit Test Bundle, name it, and add it to the iPhone project.

Set the target of the unit test to the currently activated target.

For ease of organization, you can create a new group to place test files. Add the test file, select the new file, and select iPhone OS-Cocoa Touch Class-Objective-C test case class. Pay special attention to add the file to the target of the unit test in subsequent naming, you can select only one option.

After the creation, modify the test file as follows:

Objective-c code

 
 
  1. // Header file
  2. # Import <SenTestingKit/SenTestingKit. h>
  3. # Import <UIKit/UIKit. h>
  4. @ Interface testfirst: SenTestCase
  5. {
  6. }
  7. -(Void) testFirst;
  8. @ End
  9. // Implementation file
  10. @ Implementation testfirst
  11. Int get (int I)
  12. {
  13. Return I;
  14. }
  15. -(Void) testFirst
  16. {
  17. STAssertTrue (get (0), @ "Must Fail ");
  18. }
  19. @ End
  20.  
  21. // Header file
  22. # Import <SenTestingKit/SenTestingKit. h>
  23. # Import <UIKit/UIKit. h>
  24.  
  25. @ Interface testfirst: SenTestCase
  26. {
  27. }
  28. -(Void) testFirst;
  29. @ End
  30. // Implementation file
  31. @ Implementation testfirst
  32. Int get (int I)
  33. {
  34. Return I;
  35. }
  36.  
  37. -(Void) testFirst
  38. {
  39. STAssertTrue (get (0), @ "Must Fail ");
  40. }
  41. @ End

Note that you need to import the SenTestingKit framework. This framework is not in the list. You must specify the path when adding it. on the local machine, it is/Developer/Library/Frameworks/SenTestingKit. framework.

Logical test procedure:

Select build. If there is no error, the compilation is successful. If there is an errorXcodeCompilation failed and pointed out the error.

The function signature to be tested must be (void) testXXX;

Summary: in-depth analysisIPhoneMedium ProjectUnit TestThis article is helpful. For more information, see edit recommendations.

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.