ios - How to write tests to UIActionSheet and its button -


I am trying to write unit test for my visual controller This is the first view controller of my app and top left hand There is an 'Account' button on the corner. Pressing it will be presented an action sheet, for which there are now two buttons:

  • Logout
  • Change the passcode

I want to To write a test for this functionality:

  • Pressing the 'Account' button should display the action sheet.
  • Action sheet will have two buttons: 'Logout' & amp; 'Change passcode'
  • Pressing the 'Logout' button should cause the user to log out.
  • Pressing the 'Change Passcode' button should present the passcode view controller in passcode mode. / Li>

The problem is that if I trigger the account button in my test, then it will try to present an action sheet which fails because under the test the controller's view Not a part of the window, and this means that I can not write any of the other tests.

are proposed, but they need to make a pontoon as a UNACSAT with the same interface, and do something like this in my view controller:

  // . File @ property (non-standard, strong) class action-off class; // after pressing // file in // // self.actionSheetClass operation = [[self.actionSheetClass alloc] init ...];  

This is a very unnatural way of writing code - one of the time when you get your code out of shape, just to make it checkable. I get better test coverage at the cost of readability. I will have my cake, eat it, and then bake some other cakes and eat it too

Do anyone know that I can use my UIActionSheet How can I test on the basis?

Update

Commenting after Michael Sibu, I started searching for how I can use OCMock to test all the things that I want to test I am The problem with the approach in that thread is that the number of buttons can not be tested, nor can their actions be done, the culprit is zero-ended logic. Even with all the acrobatics which makes the objective-runtime possible, it is actually to test the impossible buttons and their actions

This is the reason :

  1. You can not show an action sheet because there is no visualization of your tests that are being displayed. So if the view controller is using some code like - (zero) showActionSheet {UIActionSheet * actionSheet = [[UIActionSheet alloc] initWith ...]; [Action sheet show invoice: self.view]; } This means that if there is no reference to its implementation sheet, then you will not be able to get a reference of the action sheet in your tests without any joke. No reference, no checking button.

  2. you initWithTitle: rep: cancel buttonTitle: destructive buttonTunnil: other button buttons: can not stop the method of zero- / P>

  3. I tried to use the aspect of Peter Steinberger's library to add "after hook" in that method, but the vacuum-ended arguments again caused problems because of the aspect Usage NSInvocation passing the message on the original method For areas, which means that the effort will be EXC_BAD_ACCESS to any use of a variable argument list before the item.
  4. Burning init method? This can be an option, but I have not tried so far and will not have time for a while.

Is it really worth the effort? Surely not, but I think that should be testable and it should not be it should take great effort. It has definitely been educational.


Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -