Setting Up Application Testing in iPhone development



To set up an application–unit-test bundle in a project:


1. Make a copy of the target that builds the application to test by choosing Duplicate from its shortcut menu, and name it <application_name>Testing (for example, MyAppTesting). The only purpose of this target is to run application unit tests.


 


2. Add an iPhone OS unit-test bundle target to the project. Name the target <application_name>Tests


 


3. Make the MyAppTesting target dependent on the MyAppTests target by dragging MyAppTests to MyAppTesting. Making the MyAppTesting target dependent on the MyAppTests target ensures that when you build MyAppTesting, MyAppTests gets built first.


 


4. Embed the MyAppTests bundle into the MyAppTesting bundle by dragging the MyAppTests.octest product to the MyAppTesting target Copy Bundle Resources build phase.


 


5. Add a group called Tests to the Groups & Files list (if it doesn’t already exist), and select that group in the list.


6. Add a unit-test class to the MyAppTests target. Each unit-test class in the bundle makes up a test suite.


 Choose File > New, select the iPhone OS unit-test class template, and click Next.


 Name the class MyAppTests


 Select the option to create the header file.


 Ensure that MyAppTests is the only target selected in the target list.


 


7. Change MyAppTests.h so that it looks like this:


#import <SenTestingKit/SenTestingKit.h>


#import <UIKit/UIKit.h>


@interface MyAppTests : SenTestCase {


}


@end


 


8. Change MyAppTests.m so that it looks like this:


#import \"ApplicationTests.h\"


@implementation ApplicationTests


- (void) testFail {


STFail(@\"Must fail to succeed.\");


}


@end


 


9. Set the Base SDK for the project to iPhone Device 3.0 or later.


 


10. Set the active target to MyAppTesting and choose Build > Build and Run. Xcode builds your application, installs and launches it on your device, and runs the test suite, which fails. You can see the test results in the console. This outcome confirms that application unit testing is set up correctly.


 


11. Now make the test suite pass by changing the highlighted lines in MyAppTests.m:


#import \"MyAppTests.h\"


@implementation LogicTests


- (void) testAppDelegate {


id app_delegate = [[UIApplication sharedApplication] delegate];


STAssertNotNil(app_delegate, @\"Cannot find the application delegate.\");


}


@end

Editor: ankita Added on: 2013-03-07 15:44:15 Total View:324







Disclimer: PCDS.CO.IN not responsible for any content, information, data or any feature of website. If you are using this website then its your own responsibility to understand the content of the website

--------- Tutorials ---