
|
|
![]() You write your test cases for FoneMonkey in the same way you write any OCUnit test. To create a test case, simply subclass SenTestCase and use STAssertions to test for expected results. For more information on OCUnit (SenTestingKit), see Apple's Documentation. Using the FoneMonkey API, you can run FoneMonkey commands from within your test case, and you use OCUnit Let's look at an example: #import <SenTestingKit/SenTestingKit.h> #import <UIKit/UIKit.h>
#import "FoneMonkeyAPI.h"
@interface SampleTest : SenTestCase
- (void) testSample;
@end
@implementation SampleTest
- (void) testSample {
NSString* lastResult = [FoneMonkeyAPI playFile:@"Test1"];
STAssertNil(lastResult, lastResult);
}
@endFoneMonkeyAPI.h can be found in the include folder of the FoneMonkey distribution download. You run a FoneMonkey script from a test case by calling runScript:(NSString*)script, where script is the name of a FoneMonkey script stored in your application's Documents directory. runScript: returns nil if the script runs successfully. For example, in the script above we call:
NSString* lastResult = [FoneMonkeyAPI playFile:@"Test1"];
If the script fails for any reason, runScript: returns the message generated from a failed Verify command, or other error message. You need to explicitly add an assertion to test for a non-nil result, and display the returned message if it's non-nil as follows: STAssertNil(lastResult, lastResult); You can of course do more in your test case than simply run a script and test its result. You can include addition programming logic and assertions, and run multiple scripts. Using the FoneMonkey API, It is also possible to build scripts programatically at run time, rather than running a script previously saved.
|