Creating just a view controller will lead to the navigation controller (and thus, the bar) being nil
. The solution is to create a navigation controller:
- (void)testNavBarColourOfMasterViewController
{
VAGMasterViewController *mvc = [[VAGMasterViewController alloc] init];
UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:mvc];
[mvc view];
XCTAssertEqualObjects([[[mvc navigationController] navigationBar] barTintColor], [UIColor whiteColor]);
}
Also, it is not good practice to access the navigation controller or its properties (in this case, bar) in viewDidLoad
, because the view loading may be triggered before the navigation controller has linked itself with the view controller, causing issues.