title: Unit testing button click is not working
body: <p>I have added a button programmatically and I have to run unit test for automation process. We dont have much UI components so we dont use UI testing bundle.</p>
  
  <p>Added button in code </p>
  
  <pre><code>self.proceedButton.frame = CGRectMake(0.0, 0.0, (buttonContainerWidth * 0.75), (buttonContainerHeight * 0.3));
  self.proceedButton.center = CGPointMake(self.buttonContainer.center.x, CGRectGetHeight(self.proceedButton.frame));
  self.proceedButton.layer.cornerRadius = CGRectGetHeight(self.proceedButton.frame) / 2;
  self.proceedButton.layer.masksToBounds = YES;
  self.proceedButton.titleLabel.font = proceedFont;
  [self.proceedButton addTarget:self action:@selector(onAcceptClicked) forControlEvents:UIControlEventTouchUpInside];
  </code></pre>
  
  <p>Test:</p>
  
  <pre><code>[vc viewDidLoad];
  NSString *selector = [[vc.proceedButton actionsForTarget:vc forControlEvent:UIControlEventTouchUpInside] firstObject];
  XCTAssert([selector isEqualToString:@"onAcceptClicked"]);
  [vc.proceedButton sendActionsForControlEvents: UIControlEventTouchUpInside];
  </code></pre>
  
  <p>This fails if I comment out the <code>[self.proceedButton addTarget:self action:@selector(onAcceptClicked) forControlEvents:UIControlEventTouchUpInside];</code> line so it seems the test is written correctly.</p>
  
  <p>However <code>sendActionsForControlEvents:</code> is not entering <code>onAcceptClicked</code> method in the test. </p>
  
  <p>Why this is happening? Is it possible that unit test is finishing before <code>onAcceptClicked</code> getting actually called? </p>