0

I've got a UIButton subclass, which does override hitTest method. I need to test if tapping at specific points does what I require. I intended to make this implementation inside the unit tests.

However like it's not a problem to make a simulation of general button click, I have no idea how to simulate this click in specific coordinates. Any help/hint please?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Nat
  • 12,032
  • 9
  • 56
  • 103
  • I've never needed to do this, but instead of looking for a "click", maybe search for "tap recognizer". I did and found this 3 year old SO question that may give you a route to go (3 options in the solution). [link]http://stackoverflow.com/questions/14094691/uitapgesturerecognizer-programmatically-trigger-a-tap-in-my-view#14095468 –  Nov 25 '16 at 13:24
  • @dfd Neither of these allows to select given point. – Nat Nov 25 '16 at 13:27

1 Answers1

0

Well, in fact, it was easier to make a test for it in UI Tests instead of Unit Tests.

HOWEVER: If you want to do it as well, think that your UI component may be used in other classes, in which you probably won't "copy" all of the tests. Later someone can remove the use of your UI component from origin place AND as a result - the UI tests. In this situation, your UI component WILL be used but WON'T be tested!

So my recommendation is to create a subproject with the component which will contain the tests. Another benefit is that you won't wait until these additional UI tests complete in your main project.

Nat
  • 12,032
  • 9
  • 56
  • 103