?????????????????? test ?????????????????????ο飬??????????е?????????
????1.???????????????????? ;
????2.?????????????? ;
????3.??????????У?????????????????磬??????????е???????(????:???????????????????) ??????????в??????е????????????????????????????!??????鯔??!
????4.????????????????????"????????"???????????????????!
????5.?????????д?? NSLog???????????????????~?????????????????????????????в??????? NSLog ??????????????! NSLog ?????????????????????ж???????????????????'???? --> XCTAssert '???????"??????"????????????!
????6.?????Щ????????е??????: ??????????!??Щ?????????????????????????????????????????!???鷳!???????????????д???????????????????!
???????:
????1.???????е??????????е??????! ???????????????????:??????? " ??????????????"
????<1>???????з??????y??в???!
????<2>.h???(??????)?е???????????????!
????<3>???к? UI ?й?????????????в??????????ò???!??? UI ???????????????????????????????Щ????????????????????????????????????!
????2.MVVM ?????????:????С????????????????????? ViewModel ?У????????????????????ó??????????????!
????3.????????????????????????70%????!??????????????????!???????????????????????!
????<1>???????? AFNetworking?? ???? AFN ?????2?????е???????飬??????????д?? Codecov--->???? ????????????!
????<2>??????? YYModel ?е???????????????????99%?????????????????????????????????????!
????????Щ???????:
????1.XCTAssert ???? ;
????2.XCTAssert(age == person.age ?? @"???????") ????????? : ??? age == person.age ??????????????????"???????":
????3.???????????????????NSTimeInterval start = CACurrentMediaTime() ??? NSLog(@"^^ --> %f <-- ^^" ?? CACurrentMediaTime() - start) ;????????????????????!
????????????????????·???!!!????????? testPerformanceExample ????????~??????????????10????? for ?????????????ε???????????(???????????)

????4.??????????????????????????·???:expectation-->??? ;
????XCTestExpectation *expectation = [self expectationWithDescription:@"?????? Person"] ; //???????expectation ??? ;
????[expectation fulfill] ;//????????? ;
????[self waitForExpectationsWithTimeout: 1.0f handler:^(NSError * _Nullable error) {
????}] ;//????????://?????????? 1.0f ??????????????????????:
????PersonTests.m ???
#import <XCTest/XCTest.h>
#import "Person.h"
@interface PersonTests : XCTestCase
@end
@implementation PersonTests
/**
??ε??????????????????????????????????:
??????:[[self alloc] init] ;
*/
#pragma mark - setUp ????
- (void)setUp {
[super setUp];
// Put setup code here. This method is called before the invocation of each test method in the class.
//  ?????????????????.???????????????е????????????(?? test ????????)????????.
}
/**
??ε???????????????????:
?????? dealloc ;
*/
#pragma mark - tearDown ????
- (void)tearDown {
[super tearDown];
// Put teardown code here. This method is called after the invocation of each test method in the class.
// ?????????????????.???????????????е?????????????? test ????????)???????.
}
//?????????????? test ?????????????????????ο?:
/**
1.???????????????????? ;
2.?????????????? ;
3.??????????У?????????????????磬??????????е???????(????:???????????????????) ??????????в??????е????????????????????????????!??????鯔??!
4.????????????????????"????????"???????????????????!
5.?????????д?? NSLog???????????????????~?????????????????????????????в??????? NSLog ??????????????! NSLog ?????????????????????ж???????????????????'???? --> XCTAssert '???????"??????"????????????!
6.?????Щ?????????`???????`:
??????????!??Щ?????????????????????????????????????????!???鷳!???????????????д???????????????????!
???:
1.???????е??????????е??????! ???????????????????:`???????` --> ??????????????!
<1>???????з??????y??в???!
<2>.h???(??????)?е???????????????!
<3>???к? UI ?й?????????????в??????????ò???!??? UI ???????????????????????????????Щ??????????????????????????????`???????`!
2.MVVM ?????????:????С????????????????????? ViewModel ?У????????????????????ó??????????????!
3.????????????????????????70%????!??????????????????!???????????????????????!
<1>???????? AFNetworking?? ???? AFN ?????2?????е???????飬??????????д?? `Codecov`--->???? `????????????`!
<2>??????? YYModel ?е???????????????????99%?????????????????????????????????????!
*/
#pragma mark - ???? Person ???
- (void)testNewPerson {
[self checkPersonWithDictionary:@{ @"name":@"zhangsan" ?? @"age":@26 }] ;
[self checkPersonWithDictionary:@{ @"name":@"zhangsan" }] ;
//?????:
[self checkPersonWithDictionary:@{}] ;
[self checkPersonWithDictionary:@{ @"name":@"zhangsan" ?? @"age":@26 ?? @"title":@"leader" }] ;
//???????????:
[self checkPersonWithDictionary:@{ @"name":@"zhangsan" ?? @"age":@500 ?? @"title":@"leader" }] ;
[self checkPersonWithDictionary:@{ @"name":@"zhangsan" ?? @"age":@-1 ?? @"title":@"leader" }] ;
//??????????????????????????????!
}
#pragma mark - ??? Person ???????
- (void)checkPersonWithDictionary:(NSDictionary *)dictionary {
Person *person = [Person personWithDictionary:dictionary] ;
NSLog(@"%@" ?? person) ;
//?????????:
NSString *name = dictionary[@"name"] ;
NSInteger age = [dictionary[@"age"] integerValue] ;
//XCTAssert:???? ;
//1.???????:
//??? [name isEqualToString:person.name] ??????????????????"?????????":
XCTAssert([name isEqualToString:person.name] || person.name == nil ?? @"?????????") ;
//2.???????:
//??? age == person.age ??????????????????"???????":
if (person.age > 0 && person.age < 100) {
XCTAssert(age == person.age ?? @"???????") ;
} else {//??????????????????????????????? 0 ????????????:
XCTAssert(person.age == 0 ?? @"??????") ;
}
}
//Performance: ???? ; ???? ;
/**
1.?????????????? 10 ?? ?? ?????????????????? ;
2.?????????????д?? ?? ??????????? ;
???:
"???????!????2?!" ---> ???????????????~д??????д?????????????!??????????????????!
*/
#pragma mark - testPerformanceExample ???????
- (void)testPerformanceExample {
// This is an example of a performance test case.
// ???????????????????:
[self measureBlock:^{
// Put the code you want to measure the time of here.
// ????????????????????????:
NSTimeInterval start = CACurrentMediaTime() ;
for (int i = 0; i< 10000; i++) {
[Person personWithDictionary:@{@"name":@"zhangsan" ?? @"age":@20}] ;
}
NSLog(@"^*^ --> %f <-- ^*^" ?? CACurrentMediaTime() - start) ;
}];
}