Testing Parcelable and Serializable classes

Matthew Dolan
6 min readAug 2, 2019

It’s hard to write an app in Android without coming across the need to serialise data using either Parcelable or Serializable. In this article, we will explore why at Babylon Health we test our implementations of these interfaces even when using code-generation tools like @Parcelize, and the tools we use to help us write tests that work for all our classes.

Why test Parcelable and Serializable implementations

Our codebase contains over 50 Parcelable and Serializable objects. When I started at Babylon, most of these were implemented using AutoParcel; however, due to build performance issues using annotation processors, I re-wrote most of these by hand.

It is worth noting that at the time @Parcelize was still experimental, so we chose not to use it. Of course, this is now officially released, and our codebase has since evolved to use it.

Aside from writing less code, another great advantage of using @Parcelize is that if an object cannot be parcelled the IDE complains. Thus, reducing the chances of your app crashing in production.

--

--

Matthew Dolan

Matt Dolan has been eating doughnuts and developing with Android since the dark days of v1.6.