OkCupid Jul 27, 2020

Improve Android Testability with Fakes and Factories

Article Summary

Brian Plummer from OkCupid hit a wall adding a simple analytics event: his unit tests broke because static constructs were calling the analytics library directly. Here's how he fixed it with a pattern that made the code more testable.

OkCupid's engineering team faced a common legacy code problem: tightly coupled analytics that broke tests. The existing pattern had ViewModels calling analytics directly through static objects, making unit testing impossible without invoking the actual analytics SDK in the JVM.

Key Takeaways

Critical Insight

By abstracting analytics behind interfaces and using fakes instead of mocks, the team made their ViewModels testable while keeping event processing logic verifiable in isolation.

The article reveals why putting event processing logic in either the ViewModel or the analytics layer creates problems, and where it actually belongs.

Recent from OkCupid

Related Articles