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.
Added button in 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];
Test:
[vc viewDidLoad];
NSString *selector = [[vc.proceedButton actionsForTarget:vc forControlEvent:UIControlEventTouchUpInside] firstObject];
XCTAssert([selector isEqualToString:@"onAcceptClicked"]);
[vc.proceedButton sendActionsForControlEvents: UIControlEventTouchUpInside];
This fails if I comment out the [self.proceedButton addTarget:self action:@selector(onAcceptClicked) forControlEvents:UIControlEventTouchUpInside]; line so it seems the test is written correctly.
However sendActionsForControlEvents: is not entering onAcceptClicked method in the test.
Why this is happening? Is it possible that unit test is finishing before onAcceptClicked getting actually called?
Aucun commentaire:
Enregistrer un commentaire