[英]What am I doing wrong for this unit test?
我正在嘗試在iOS應用上測試我的重置按鈕。 基本上,在reset方法中,它將重置所有文本字段。 因此,我通過分配record.salesamount.text一串數字然后執行resetEverything對其進行測試。 但是,在NSLog中,之前和之后的日志都為(空)。 我究竟做錯了什么?
- (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");
}
使用前初始化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");
}
您record.SalesAmounttext
如果在你需要自己初始化它,你不是從情節提要/廈門國際銀行在加載文本的情況下outlet.But自動初始化。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.