2

I want to test below method :

- (void)myMethod
{
    self.contact = nil;
    [self performSegueWithIdentifier:@"segue id" sender:self];
}

This is what I do in test class :

- (void)testMyMethod
{
    // Call method to test
    [testClass myMethod];

    // Tests
    GHAssertNil(testClass.contact, @"contact should be nil.");
}

Running the test gives me error :

Reason : Receiver (<RS_MainViewController:0x126b6330>) has no segue with identifier 'segue id'

Why I get this error and what is the solution?

Geek
  • 8,280
  • 17
  • 73
  • 137

1 Answers1

0

I had to load the view controller from the storyboard in my test and then it worked. The I was able to call viewDidLoad in my tests and continue.

UIStoryboard* storyboard = [UIStoryboard storyboardWithName:@"MyStoryboard" bundle:nil];
UIViewController* controller = [storyboard instantiateViewControllerWithIdentifier:@"MyViewControllerId"];
AAAMyViewController* viewController = (AAAMyViewController*)controller;

I also had to go into the storyboard and add a Storyboard ID for this view controller (MyViewControllerId).

Anthony Elliott
  • 2,941
  • 5
  • 29
  • 42