How to unit test subclasses of UIGestureRecognizer?

Has anyone successfully tested subclasses of UIGestureRecognizer? What approach do you use or recommend, if so? How are you going to synthesize events, if so?

+4
source share
3 answers

it's not really unit testing, but the best way you can test your user interface is to use Automation. Basically you write javascript and then run it in Tools under Automation.

This is not well documented and there are almost no textbooks. Get ready for an upset.

0
source

I use Cedar and plan to test custom UIGestureRecognizers by mocking NSTouch objects, linking them as a set, and making the corresponding calls to various UITouchGestureSubclass items. This module checks the user class. The behavior of the parent class I is executed by calling the action method registered in the UIGR subclass.

0
source

I have not yet seen a good solution for testing modules, and I will need to find it soon, so I would like to see or get a better answer.

As @tooluser said, you could provide β€œnice” layouts for UITouch objects. Since there is no open constructor for UITouch supplying β€œreal” UITouch instances, it is complex and will rely on private API calls. Unfortunately, since these touches must go through the code of a framework that you don't see or control, you should hope that your layouts really match all the expected UIT behavior that they double (including any personal behavior that we can't see). It makes me nervous.

Alternatively, you can follow @Sulthan's solution and test your gesture recognizers with integration tests for the UI. This is the approach I have used so far. Use a UIAutomation or a third-party test environment, such as Frank or KIF , to generate interactions with views and to claim that gesture recognizers work as expected. This may at least allow you to test the resolver separately (even if not in the true unit test).

Usually I want to have some integration tests to make sure that the interaction between several recognizers in user views behaves correctly, so I don’t think this approach is too bad, but it would be nice to really check the recognizer development test at the unit level (for the test run time if nothing else).

0
source

All Articles