iOS UnitTest???????
??????????? ???????[ 2017/6/7 9:58:53 ] ??????????????? ??????? ????????
????3.??????
??????Xcode6????汾???沢???????XCTest???????Xcode??????????????????RunLoop??????????while???????????????????????timeout.??Xcode6??????????????XCTestExpectation??????????????????????????????????????????????????????????????????????????????????????GCD??
????model?????
????(void)testAsync
????{//??????
????NSDictionary*dict=@{
????@"name":@"MrLi"??
????@"age":@28??
????@"flags":@987
????};
????TestModel1*model=[[TestModel1alloc]initWithDictionary:dict];
????XCTAssertNotNil(model);
????[modelasyncConvertToData];
????while(model.data==nil){
????CFRunLoopRunInMode(kCFRunLoopDe
????faultMode??0.01??YES);
????NSLog(@"waiting");
????XCTAssertNotNil(model.data);
????NSLog(@"convertfinish%@"??model.data);
????}
????model?????
????(void)asyncConvertToData
????{
????dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT??0)??^{
????NSDictionary*modelJSON=nil;
????for(NSIntegeridx=0;idx<20;
????idx++){
????modelJSON=[selfmodelToDictionary];
????[selfsetValuesForKeysWithDictionary
????:modelJSON];
????[NSThreadsleepForTimeInterval:0.001];
????}
????_data=[NSJSONSerializationdataWith
????JSONObject:modelJSONoptions:NSJSON
????WritingPrettyPrintederror:nil];
????});
????}
????e.g.?·???
??????Xcode6???????XCTestExpection???????XCTest?????????????????(testexpection)????????????????????????(XCTestExpectation)???????????????????????????????????????????????е???????????XCTestExpection???е?fulfill???????????????
?????????ò???????(?????)???????????XCTestCase??waitForExpectationsWithTimeout:handler:?????????????????????????????????в???????fulfill???????????????е?????????????????????????????е?handler?????????????block??block??????д?д?????????е?????????????????????У???a?????????????????????????????b?????????????????????????????????????block????????????У???
????????
????(void)testAsyncOutTime{
????XCTestExpectation*ex=[selfexpectationWithDescription:@"wgj001"];
????NSURL*url=[NSURLURLWithString
????:@"https://www.baidu.com"];
????NSURLSession*session=[NSURLSessionsessionWithConfiguration:[NSURLS
????essionConfigurationdefaultSession
????Configuration]];
????NSURLRequest*request=[NSURLRequest
????requestWithURL:url];
????NSURLSessionTask*task=[session
????dataTaskWithRequest:requestcompletion
????Handler:^(NSData*_Nullabledata??
????NSURLResponse*_Nullableresponse??
????NSError*_Nullableerror){
????NSLog(@"url???????");
????[exfulfill];//??????????????????
???????????в???????fulfill?????????
??????????е??????????????????????
????}];
????[taskresume];
????[selfwaitForExpectationsWithTimeout:
????1handler:^(NSError*_Nullableerror){
????if(error){
????NSLog(@"wati:%@"??error);
????}
?????????
????1??XCTFail(...):???????п??????????????????????????????????????????????????????????????????????????????????????????????????и????????????????????????????????????????????????λ???????????????????????????????????????????????л???????Щ?????else??????????ó??????????????????????XCTFail???????else???檔
????2??XCTAssertNil(expression??...)/XCTAssertNotNil(expression??...):?ж??????????????nil??XCTAssertNil(?????nil????????)??XCTAssertNotNil?????????nil????????????????...???????????????????????????????е??????????????
????3??XCTAssert(expression??...)?????expression??????????е????true?????????????????????????????????console??????????format?????.
????4?????????XCTAssert??????????????????????????????????????????????????????????????????????????Щ?????????????
????a.Bool????
????????bool??????????????????bool???????????XCTestAssertTrue????XCTestAssertFalse??
????XCTAssertTrue(expression??format...)
????XCTAssertFalse(expression??format...)
????b.??????
???????????????????????????XCTAssert[Not]Equal:
????XCTAssertEqual(expression1??
????expression2??format...)
????XCTAssertNotEqual(expression1??
????expression2??format...);
?????ж????????????XCTAssertEqualObjects(expression1??expression2??...)??XCTAssertNotEqualObjects(expression1??expression2??...)
??????Double??Float??????????????XCTAssert[Not]EqualWithAccuracy????????????????
????XCTAssertEqualWithAccuracy(expression1??
????expression2??accuracy??format...)
????XCTAssertNotEqualWithAccuracy(expression1??
????expression2??accuracy??format...)
????e.g.XCTAssertEqualWithAccuracy(12??14??1??@"wgj")????????????12??14??????????????趨???1??
????XCTAssertGreaterThan[OrEqual]&XCTAssertLessThan[OrEqual]???????????????????????????????==with>??>=??<?????<=
????5????????
????a.
????XCTAssertThrows(expression??...):????????????????????????????e.g.XCTAssertThrows([modelonlyTest]??@"wgj01");??????model???????????????????????????????????????????????????????
????b.
????XCTAssertThrowsSpecific(expression??exception_class??...):????????????????????????????NSException??????????????????
????e.g.
????XCTAssertThrowsSpecific([modelonlyTest02]??NSException??@"wgj001");--onlyTest02?????????????б?????onlyTest02????δ?????????δ????????????????????NSException?????????????????NSException??????????????????
????c.
????XCTAssertThrowsSpecificNamed(expression??exception_class??exception_name??...)??????????????????????????????NSException?????????????????????????????????????????????
????e.g.
????XCTAssertThrowsSpecificNamed([modelonlyExceptionTest]??NSException??@"???????"??@"wgj002");
????model?е?????????
????@throwexx;
????????????????????????
??????????
????XCTAssertThrowsSpecificNamed([modelonlyExceptionTest]??NSException??@"???д??????"??@"wgj002");??????????????????????????
???????????????????????漰???????????????????SPASVOС??(021-61079698-8054)?????????????????????????
??????
iOS???????mocha??chai??sinon??istanbul???????????????????????????????????????д?????Java????????7??????Android?????????Robolectric3.0????(?)???Kiwi?????????????????????????????????Python?????????????????????????????????????Controller????????д?????????10???????????????????Angular????????????Component??Directive??Pipe ???ServiceAndroid????????????????????????????????--Mockito??????Vue?????????????????Vue ????????????????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11????????
?????????App Bug???????????????????????Jmeter?????????QC??????APP????????????????app?????е????????jenkins+testng+ant+webdriver??????????????JMeter????HTTP???????Selenium 2.0 WebDriver ??????