Menu

1 / 5

Which buttons have your UI tests never tapped? Measuring UI element coverage in XCUITest

DEV Community: swift·Sergey Yakimov·6 days ago
#RHVQbNQv
#devtoswift#devto#dev#selector#test
Long article (4948 words) — no AI summary yet.
Reading 0:00
15s threshold

We have about 570 UI tests written in XCUITest. One day someone on the team asked: how much of the app do they actually cover? Not lines of code. The question was whether the tests touch every element on every screen.

I couldn't find a ready-made way to measure that, so I built one. A recorder in the test target (about 380 lines of Swift plus two lines in the base test class) logs which elements the tests access and how. A Python script matches that against the real screen hierarchy and builds an HTML report. First full run: 60% of elements are touched by at least one test, and 138 buttons, switches and links are never tapped by anything.

This post covers how the data is collected, why the tool initially broke the very tests it was measuring, and how much noise I had to clean up before the numbers became trustworthy. What to do with the results is a separate post.

Why not Code Coverage

The first suggestion on the team was to turn on Code Coverage in the test plan and look at the Xcode report.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.