How One Kotlin Keyword Broke Our UI Automation
11 approvals, green tests, and a silent UI failure.
1The Root Cause
A misuse of a Kotlin keyword caused UI automation tests to fail silently. Using apply instead of let led to incorrect test results.
2Code Review Process
The faulty code was reviewed and approved by 11 different engineers. The code's idiomatic Kotlin appearance masked the error.
3Misleading Test Results
While tests remained green, UI components did not contain the correct text. This delayed the detection of the issue.
4Difference Between apply and let
apply returns the original object, while let returns the result of the block. This difference created a critical error in UI tests.
5The Mechanism of the Bug
The applyIf function silently ignored text checks. This caused tests to approve incorrect components.
6Solution: Using letIf
Replacing apply with letIf ensured correct text checks. This fixed the error.
7API Redesign
The API was redesigned to prevent reintroduction of the bug. This ensured similar errors would not compile.
8Testing the Test Infrastructure
Testing the matchers themselves prevented similar errors. This increased the reliability of the test infrastructure.
9Team Communication and Responsibility
11 approvals diffused responsibility. This highlighted the need for more effective code review processes.
10Lessons Learned
This incident emphasized the importance of correct Kotlin scope function usage and continuous testing of test infrastructure.
Original article: ProAndroidDev - Medium — Kotlin'deki Tek Bir Keyword Nasıl UI Otomasyonunu Bozdu?