Unit Test Gesture Recognizers in Swift

Steven Curtis
3 min readMay 19, 2023

It’s possible!

Photo by Alexandru Zdrobău on Unsplash

Difficulty: Beginner | Easy | Normal | Challenging

Prerequisites:

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).

The subclass

Click for Gist

--

--