Bukalapak Mar 9, 2021

Speeding Up Android Unit Tests with Test Sharding on GitLab CI

Article Summary

Fadel Trivandi Dipantara from Bukalapak faced a brutal reality: 3,000+ test classes taking 2.5 hours to run. His team couldn't ship fast enough, and traditional solutions kept failing.

Bukalapak's Android codebase spans 18,000+ Kotlin classes across 200+ modules. The engineering team tried multiple approaches to speed up their CI pipeline: testing only changed modules (broke dependent code), testing affected modules (caused timeouts), and parallelizing by module type (uneven distribution). Each solution created new problems.

Key Takeaways

Critical Insight

By distributing modules across nodes based on test count rather than module type, Bukalapak achieved 30 to 50% faster CI runs while maintaining accurate code coverage.

The article includes the complete Ruby scripts and GitLab CI configuration you can adapt for your own modularized Android project.

About This Article

Problem

Bukalapak's test pipeline had uneven job distribution. Fast unit tests finished in 30 minutes while UI tests took 1 hour, which meant the entire pipeline had to wait. On top of that, empty test jobs still used 5 minutes of runner time just for global setup scripts.

Solution

Bukalapak implemented test sharding with module-level distribution. Ruby scripts count tests per module and assign them evenly across nodes, which prevents any single node from becoming a bottleneck. The approach also preserves Jacoco coverage accuracy.

Impact

The implementation improved speed by 30% for feature module changes and 50% for library module changes. Instead of using a fixed number of nodes, the system now allocates only the runners it actually needs based on test volume.

Recent from Bukalapak

Related Articles