Tokopedia Andrean Lay Apr 19, 2022

Stop Wasting Time on Unit Testing: How Tokopedia Achieved 8X Faster Results | by Andrean Lay | Tokopedia Engineering | Medium

Article Summary

Tokopedia's iOS team was drowning in 30-minute unit test cycles with 65 developers fighting over 9 CI/CD machines. They cut that time by 8X.

Andrean Lay from Tokopedia Engineering shares their journey from running all unit tests sequentially to implementing selective testing. With hundreds of test targets and tens of thousands of test cases, their modular Bazel-based iOS app needed a smarter approach.

Key Takeaways

Critical Insight

By testing only what changed plus its dependents, Tokopedia reduced unit test time from 30+ minutes to under 5 minutes on average.

The article includes detailed flowcharts showing exactly how they query file changes and map them to Bazel targets for selective execution.

About This Article

Problem

Tokopedia's iOS app on Bazel had hundreds of test targets, and the build process overhead repeated for each one. This made test times unpredictable, ranging anywhere from 20 to 35 minutes with occasional spikes.

Solution

Andrean Lay's team built a three-step approach to selective testing. They compared file changes, extracted affected target paths from BUILD files, and used Bazel's allrdeps command to find reverse dependencies. This way they only ran the modules that actually changed.

Impact

Selective testing cut median unit test duration down to 250 seconds. When changes only touched non-code files like GitHub code owner configurations, tests ran in zero seconds. Overall, this achieved an 8X improvement in speed.