我有 ABCD.m 类,如下所示
**ABCD.m**
@property (nonatomic, strong) UIButton *button;
@property (nonatomic, strong) NSString *string;
- (void) firstMethod;
- (void) setTheButtonWithBool:(BOOL)var1 withString:(NSString *)var2;
-(void) firstMethod {
// Alloc init button
self.button.enabled = NO;
}
- (void) setTheButtonWithBool:(BOOL)var1 withString:(NSString *)var2 {
self.button.enabled = var1;
self.string = var2;
}
还有另一个类 Test.m(XCTestCase 的子类)来编写 ABCD.m 的单元测试用例
**Test.m** //Sub-class of XCTestCase
//Extension
@interface ABCD.m ()
@property (nonatomic, strong) UIButton *button;
@property (nonatomic, strong) NSString *string;
- (void) firstMethod;
- (void) setTheButtonWithBool:(BOOL)var1 withString:(NSString *)var2;
@end
@interace Test : XCTestCase
- (void)testSomeMethod {
ABCD *abcd = [ABCD alloc] init];
BOOL *var1 = YES;
NSString *var2 = @"StackOverFlow";
[abcd firstMethod];
[abcd setTheButtonWithBool:var1 withString:var2];
nslog(@"Result1 :%hhd", self.abcd.button.isEnabled); -----
nslog(@"Result2: %@", self.abcd.string); -----
// Assert statement
}
输出:
结果 1:否
结果 2:StackOverFlow
当我设置属性“字符串”时,它被设置为“StackOverFlow”。但是对于 UIButton 属性“按钮”,它没有设置为“否”。为什么我不能设置 UIButton 的“启用”属性,因为我可以从 Test.m 类设置 ABCD.m 的 NSString