Better Android Testing at Airbnb (Part 4: Testing ViewModels)
Article Summary
Airbnb built a testing framework so elegant that their ViewModels tests read like plain English. Here's how they made testing actually enjoyable.
Eli Hart from Airbnb Engineering shares their custom unit testing framework for Android ViewModels. The approach transforms verbose test code into a clean DSL that prioritizes developer experience without sacrificing flexibility.
Key Takeaways
- Tests follow one rule: single function call with state input produces state output
- Simple syntax: setText test is just 3 lines with withParams and expectState
- Network assertions built in: validate API calls and response handling together
- Auto-generated test cases for basic setters test multiple values automatically
- IntelliJ plugin generates test scaffolding alongside new ViewModels
Critical Insight
Airbnb reduced testing friction across hundreds of modules with a DSL that makes ViewModel tests readable and maintainable.