??????????????У???????????testModelConvert
????????????????????json???????????????
- (void)testModelConvert
{
NSString * json = @"{"name":"SindriLin"??"age":22??"flags":987654321}";
NSMutableDictionary * dict = [[NSJSONSerialization JSONObjectWithData: [json dataUsingEncoding: NSUTF8StringEncoding] options: kNilOptions error: nil] mutableCopy];
LXDTestsModel * model = [[LXDTestsModel alloc] initWithDictionary: dict];
XCTAssertNotNil(model);
XCTAssertTrue([model.name isEqualToString: @"SindriLin"]);
XCTAssertTrue([model.age isEqual: @(22)]);
XCTAssertEqual(model.flags?? 987654321);
XCTAssertTrue([model isKindOfClass: [LXDTestsModel class]]);
model = [LXDTestsModel modelWithName: @"Tessie" age: dict[@"age"] flags: 562525];
XCTAssertNotNil(model);
XCTAssertTrue([model.name isEqualToString: @"Tessie"]);
XCTAssertTrue([model.age isEqual: dict[@"age"]]);
XCTAssertEqual(model.flags?? 562525);
NSDictionary * modelJSON = [model modelToDictionary];
XCTAssertTrue([modelJSON isEqual: dict] == NO);
dict[@"name"] = @"Tessie";
dict[@"flags"] = @(562525);
XCTAssertTrue([modelJSON isEqual: dict]);
}
????????
????????????????????????н??е??????????????????????????????????????????????????????
????????while()??????????????
//waitForExpectationsWithTimeout????????????????????????С?
#define WAIT do {
[self expectationForNotification:@"RSBaseTest" object:nil handler:nil];
[self waitForExpectationsWithTimeout:30 handler:nil];
} while (0)
#define NOTIFY [[NSNotificationCenter defaultCenter]postNotificationName:@"RSBaseTest" object:nil]
-(void)testRequest{
// 1.????????????
AFHTTPRequestOperationManager *mgr = [AFHTTPRequestOperationManager manager];
mgr.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/html"??nil];
// 2.????GET????
[mgr GET:@"http://www.weather.com.cn/adat/sk/101110101.html" parameters:nil success:^(AFHTTPRequestOperation *operation?? id responseObject) {
NSLog(@"responseObject:%@"??responseObject);
XCTAssertNotNil(responseObject?? @"???????");
NOTIFY //???????
} failure:^(AFHTTPRequestOperation *operation?? NSError *error) {
NSLog(@"error:%@"??error);
XCTAssertNil(error?? @"???????");
NOTIFY //???????
}];
WAIT  //???
}
?????????????????? ???GCD?????
- (void)downloadImageURLWithString:(NSString *)URLString
{ dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
NSURL *url = [NSURL URLWithString:URLString];
__unused Photo *photo = [[Photo alloc] initwithURL:url
withCompletionBlock:^(UIImage *image?? NSError *error) {
if (error) {
XCTFail(@"%@ failed. %@"?? URLString?? error);
}
dispatch_semaphore_signal(semaphore);
}];
dispatch_time_t timeoutTime = dispatch_time(DISPATCH_TIME_NOW?? kDefaultTimeoutLengthInNanoSeconds);
if (dispatch_semaphore_wait(semaphore?? timeoutTime)) {
XCTFail(@"%@ timed out"?? URLString);
}
}
??????? ??????
?????????????????????YYModel??AFNetworking??Alamofire?????????ж????????д?????????????д??Щ???????????????????????????Ρ?