Skip to content

Instantly share code, notes, and snippets.

@okitsutakatomo
Created October 14, 2013 19:16
Show Gist options
  • Save okitsutakatomo/6980543 to your computer and use it in GitHub Desktop.
Save okitsutakatomo/6980543 to your computer and use it in GitHub Desktop.
KIFとNLTHTTPStubServerを利用して最低限のIntegrationTestを実現する ref: http://qiita.com/okitsutakatomo@github/items/c06c1450f1697382e802
> pod install
Analyzing dependencies
CocoaPods 0.26.2 is available.
Downloading dependencies
Installing CocoaAsyncSocket (7.3.2)
Installing CocoaHTTPServer (2.3)
Installing CocoaLumberjack (1.6.2)
Installing KIF (2.0.0)
Installing NLTHTTPStubServer (0.4.0)
Generating Pods project
Integrating client project
[!] From now on use `KIFPractice.xcworkspace`.
> open KIFSample.xcworkspace
#import "KIFTestCase.h"
#import <KIF/KIF.h>
@interface GoToNextTests : KIFTestCase
@end
@implementation GoToNextTests
{
NLTHTTPStubServer *server;
}
//クラス実行前(setup)
- (void) beforeAll {
// make instance
server = [NLTHTTPStubServer sharedServer];
//set stub api
NSDictionary *jsonDict = @{@"status" : @"success"};
[[[server stub] forPath:@"/api"] andJSONResponse:[NSJSONSerialization dataWithJSONObject:jsonDict options:NSJSONWritingPrettyPrinted error:nil]];
}
platform :ios, '7.0'
target :KIFPracticeTests, :exclusive => true do
pod 'KIF', '~> 2.0'
pod 'NLTHTTPStubServer'
end
#import "ViewController2.h"
@interface ViewController2 ()
@property (nonatomic, strong) IBOutlet UILabel *status;
@end
@implementation ViewController2
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (IBAction)didSelectConnect:(id)sender
{
NSURL *api = [NSURL URLWithString:@"http://localhost:12345/api"];
[NSURLConnection sendAsynchronousRequest:[NSURLRequest requestWithURL:api]
queue:[[NSOperationQueue alloc] init]
completionHandler:^(NSURLResponse *res, NSData *data, NSError *err) {
NSDictionary *jsonDict = [NSJSONSerialization JSONObjectWithData:data options:nil error:nil];
NSString *status = [jsonDict objectForKey:@"status"];
NSAssert([status isEqualToString:@"success"], @"status invalid");
}];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment