user3178926
user3178926

Reputation: 339

What am I doing wrong for this unit test?

I am trying to test my reset button on my iOS app. Basically, in the reset method, it resets all the textfields. So I am testing it by assigning record.salesamount.text a string of numbers then executing resetEverything. However, in the NSLog, I am getting (null) for both the before and after logs. 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");
}

Upvotes: 1

Views: 34

Answers (1)

codester
codester

Reputation: 37189

Intialize the record.SalesAmounttext before use.

- (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.

Upvotes: 2

Related Questions