0

enter image description here

I want to make test, but I do not know how to make it (I can use GHUnit).

enter image description here

This is the class I want to test:

Communicator.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

And this is ViewController which control Communicator class.

ViewController.h

#import "Communicator.h"

@interface ViewController : UIViewController <UITextFieldDelegate>
{
    Communicator *communicator;
}

@property (weak, nonatomic) IBOutlet UIWebView *webView;
@property (weak, nonatomic) IBOutlet UIButton *startButton;

@end

ViewController.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

Thank you for your help.

Feel Physics
  • 2,783
  • 4
  • 25
  • 38

1 Answers1

0

What is it exactly you want to test? That pressing the button causes the webview to load a URL or that the webview actually brings the URL content?

harryhorn
  • 892
  • 6
  • 8