Unit Test Gesture Recognizers in Swift
3 min readMay 19, 2023
It’s possible!
Difficulty: Beginner | Easy | Normal | Challenging
Prerequisites:
- You can use gestures in a Single View Application, and will go through a specific instance of testing an App. This is pretty much a companion article to the one where I subclassed UIImageView and UIView to incorporate gestures.
- You also need some knowledge about subclassing UIView.
Terminology
UIView: An object that manages the content for a rectangular area on the screen
The project
I’ve previously created a subclass for a UIView that gives it the ability to use gestures. This is all very nice, but how might you *test* that.
To keep this article at a reasonable length, I’ve rather snipped the functionality of the subclass — here is only has UIPanGestureRecognizer
implemented (don’t worry, the procedure we go through would be just as applicable to the other gesture recognizers).