I am new to unit testing and am trying things out.
I created a view controller with 1 button (get sum), and 3 textfields (input 2 numbers and output the sum).
int aNum = [self.firstNumber.text intValue]; int bNum = [self.secondNumber.text intValue]; sum = aNum + bNum; self.total.text = [NSString stringWithFormat:@"%i", sum]; [self dismissKeyboard]; And my testing codes:
vc = [[TestingViewController alloc] init]; vc.firstNumber.text = @"1"; vc.secondNumber.text = @"2"; [vc getSum:nil]; STAssertTrue([vc.total.text isEqualToString:@"3"], @"total should be 3"); The test failed because I have tried to work with UI elements.
My questions is: is it possible to test with UI elements like this? How would I write a test to achieve this?
Thanks guys!