Created
October 14, 2013 19:16
-
-
Save okitsutakatomo/6980543 to your computer and use it in GitHub Desktop.
KIFとNLTHTTPStubServerを利用して最低限のIntegrationTestを実現する ref: http://qiita.com/okitsutakatomo@github/items/c06c1450f1697382e802
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> 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`. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> open KIFSample.xcworkspace |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "KIFTestCase.h" | |
#import <KIF/KIF.h> | |
@interface GoToNextTests : KIFTestCase | |
@end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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]]; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
platform :ios, '7.0' | |
target :KIFPracticeTests, :exclusive => true do | |
pod 'KIF', '~> 2.0' | |
pod 'NLTHTTPStubServer' | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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