[英]What am I doing wrong for this unit test?
I am trying to test my reset button on my iOS app. 我正在尝试在iOS应用上测试我的重置按钮。 Basically, in the reset method, it resets all the textfields.
基本上,在reset方法中,它将重置所有文本字段。 So I am testing it by assigning record.salesamount.text a string of numbers then executing resetEverything.
因此,我通过分配record.salesamount.text一串数字然后执行resetEverything对其进行测试。 However, in the NSLog, I am getting (null) for both the before and after logs.
但是,在NSLog中,之前和之后的日志都为(空)。 What am I doing wrong?
我究竟做错了什么?
- (void)testResetEverything
{
RecordViewController *record = [[RecordViewController alloc]init];
record.SalesAmounttext.text = @"1234567890123456";
NSLog(@"before %@",record.SalesAmounttext.text);
[record resetEverything];
NSLog(@"after %@",record.SalesAmounttext.text);
XCTAssertEqualObjects(record.SalesAmounttext.text, nil, "Should be a nil");
}
Intialize the record.SalesAmounttext
before use. 使用前初始化
record.SalesAmounttext
。
- (void)testResetEverything
{
RecordViewController *record = [[RecordViewController alloc]init];
record.SalesAmounttext = [[UITextField alloc] init]; //Write this line before use record.SalesAmounttext
record.SalesAmounttext.text = @"1234567890123456";
NSLog(@"before %@",record.SalesAmounttext.text);
[record resetEverything];
NSLog(@"after %@",record.SalesAmounttext.text);
XCTAssertEqualObjects(record.SalesAmounttext.text, nil, "Should be a nil");
}
your record.SalesAmounttext
is automatically initialized if it is outlet.But in text cases you need to initialize it by yourself as you are not loading it from storyboard/xib. 您
record.SalesAmounttext
如果在你需要自己初始化它,你不是从情节提要/厦门国际银行在加载文本的情况下outlet.But自动初始化。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.