Yalamandarao
Yalamandarao

Reputation: 3862

How to write Kiwi test cases in for below mentioned IBAction

I'm facing the issue to right test case for below mentioned function.

-(IBAction) returnToLogin:(UIStoryboardSegue*) segue {
  NSLog(@"kiwi tested");
}

I have tried different ways but it's pass the test case

   it(@"Should unwind segue", ^{
        NSNumber *actionMethod = @([_vc respondsToSelector:@selector(returnToLogin:)]);
        [[actionMethod should] beTrue];
    });

Do you have any idea?

Upvotes: 0

Views: 133

Answers (1)

Cristik
Cristik

Reputation: 32782

In the current implementation of returnToLogin: you cannot test much, as the method is not doing anything. If the method would perform some actions, like changing the view controller hierarchy, then you would be able to assert on that behaviour.

But take into consideration the following:

  1. the signature of the IBAction is not correct, an UIStoryboardSegue cannot trigger an action.
  2. controllers are a little bit difficult to test, mainly because it involves testing UI changes
  3. try to refactor the logic that you want tested into business classes, and test those classes;
  4. Apple added support for UI testing since Xcode7 and iOS9, so if you want to test the UI you can use that

Upvotes: 0

Related Questions