So, maybe this doesn't directly answer your question on your to test [UIButton setTitle:forState:]
, but I would submit that you shouldn't test a stock Apple API. To test your logic for setting the login button title, I would actually change it so that it returns a string that in a different method will set whatever title on the button. Here's what I mean:
- (void)setLoginButtonTitleForState:(BOOL)isLoggedIn {
[_loginButton setTitle:[self buttonTitleForLoggedIn:isLoggedIn] forState:UIControlStateNormal];
}
- (NSString *)buttonTitleForLoggedIn:(BOOL)loggedIn {
return (loggedIn) ? @"Logout" : @"Login";
}
and your test would look something like this:
- (void)test_checkLoginAndSetLoginButtonAndTitle_loggedIn {
MyViewController *myViewController = [[MyViewController alloc] initWithNibName:@"MyViewController" bundle:nil];
STAssertEqualObjects([myViewController buttonTitleForLoggedIn:YES], @"Logout", @"After logging in, the 'login' button's title should be set to logout");
}