单元测试:
代码如下:
例子如下:
1 Person.h
#import
NS_ASSUME_NONNULL_BEGIN
@interface Person : NSObject
@property (nonatomic, strong) NSString *name;
@property (nonatomic, assign) NSInteger age;
- (instancetype)initWithInfo:(NSDictionary*)info;
@end
NS_ASSUME_NONNULL_END
2 Person.m
#import "Person.h"
@implementation Person
- (instancetype)initWithInfo:(NSDictionary*)info {
self= [superinit];
if(self) {
self.name= info[@"name"];
self.age= [info[@"age"]integerValue];
}
return self;}
@end
测试用例: 测试正确 绿色对勾 ✅ 测试错误 红色打❌
------测试Log
#ifdef DEBUG
#define TestLog(FORMAT, ...) fprintf(stderr,"[TEST LOG] %s\n",[[NSString stringWithFormat:FORMAT, ##__VA_ARGS__] UTF8String]);
#else
#define TestLog(...)
#endif
-----------------------------------------------------------------------------------------------------
PSDTest.m
- (void)testInitPersion {
NSDictionary *dic = @{@"name":@"test",@"test":@25};
Person*p = [[Personalloc]initWithInfo:dic];
NSAssert([p.nameisEqualToString:dic[@"name"]],@"姓名不一致");
NSAssert(p.age== [dic[@"age"]integerValue],@"年龄不一致");
TestLog(@" BLE Test Case START");
}











网友评论