Menu

1 / 5

Rewriting for Kotlin Multiplatform Without Changing Behavior: Old Code as a Test Oracle

DEV Community: kotlin·Nesim Razon·2 days ago
#XCZQObQM
#devtokotlin#devto#dev#test#code
Reading 0:00
15s threshold

I moved two small RSS reader apps and a space app to Kotlin Multiplatform so they could also run on iOS. That meant rewriting code that leaned on Android and Java classes. I did not want a single existing user to notice a difference, so I kept the old implementation in the test sources and made it argue with the new one. Here is how that went.

What had to be rewritten

Common Kotlin code cannot call Android or Java classes, and iOS has none of them. The RSS parser used XmlPullParser, the text cleanup used HtmlCompat, the dates went through SimpleDateFormat, and the space app shuffled its daily cards with java.util.Random. All four had to become plain Kotlin that compiles for both platforms.

A rewrite like this is the classic place to introduce quiet changes: a title that loses an accent, a date that shifts by an hour, a list in a different order.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.