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
- // Header file
- # Import <SenTestingKit/SenTestingKit. h>
- # Import <UIKit/UIKit. h>
- @ Interface testfirst: SenTestCase
- {
- }
- -(Void) testFirst;
- @ End
- // Implementation file
- @ Implementation testfirst
- Int get (int I)
- {
- Return I;
- }
- -(Void) testFirst
- {
- STAssertTrue (get (0), @ "Must Fail ");
- }
- @ End
-
- // Header file
- # Import <SenTestingKit/SenTestingKit. h>
- # Import <UIKit/UIKit. h>
-
- @ Interface testfirst: SenTestCase
- {
- }
- -(Void) testFirst;
- @ End
- // Implementation file
- @ Implementation testfirst
- Int get (int I)
- {
- Return I;
- }
-
- -(Void) testFirst
- {
- STAssertTrue (get (0), @ "Must Fail ");
- }
- @ 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.