Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #import <XCTest/XCTest.h>
- #import "Person.h"
- @interface ParsingJSONTests : XCTestCase
- @end
- @implementation ParsingJSONTests
- - (void)testReadingJSONFile {
- // Getting the path in the current bundle
- NSString *path = [[NSBundle mainBundle] pathForResource:@"sample" ofType:@"json" inDirectory:nil];
- if (path) {
- // create data from that path
- NSData *jsonData = [NSData dataWithContentsOfFile:path];
- NSError *error;
- if (jsonData) {
- NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:jsonData options:[] error:&error];
- if (error) {
- XCTFail(@"JSONSerialization error: %@", error.localizedDescription);
- } else {
- // create our Person object
- Person *person = [[Person alloc] initWithDict:dict];
- XCTAssertEqualObjects(person.name, @"Jane");
- XCTAssertEqualObjects(person.email, @"jane@jane.com");
- XCTAssertEqualObjects(person.phone, @"917-123-4567");
- }
- } else {
- XCTFail(@"data is nil");
- }
- XCTAssertNotNil(path);
- } else {
- XCTFail(@"file NOT FOUND");
- }
- }
- @end
Add Comment
Please, Sign In to add comment