我想做测试,但我不知道怎么做(我可以使用 GHUnit)。
这是我要测试的课程:
通讯器.h
@interface Communicator : NSObject
-(void)loadURLWithString:(NSString*)urlString withWebView:(UIWebView*)webView;
@end
Communicator.m
#import "Communicator.h"
@implementation Communicator
##### I WANT TO EXCLUDE THE WEBVIEW BELOW #####
-(void)loadURLWithString:(NSString*)urlString withWebView:(UIWebView*)webView
{
NSURL *url = [[NSURL alloc] initWithString:urlString];
NSURLRequest *r = [[NSURLRequest alloc] initWithURL:url];
[webView loadRequest:r];
}
@end
这是控制 Communicator 类的 ViewController。
视图控制器.h
#import "Communicator.h"
@interface ViewController : UIViewController <UITextFieldDelegate>
{
Communicator *communicator;
}
@property (weak, nonatomic) IBOutlet UIWebView *webView;
@property (weak, nonatomic) IBOutlet UIButton *startButton;
@end
视图控制器.m
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
communicator = [[Communicator alloc] init];
[_startButton addTarget:self action:@selector(startButtonPushed) forControlEvents:UIControlEventTouchDown];
}
- (void)startButtonPushed
{
[communicator loadURLWithString:@"http://www.apple.co.jp" withWebView:_webView];
}
@end
谢谢您的帮助。