Rewriting for Kotlin Multiplatform Without Changing Behavior: Old Code as a Test Oracle
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…
The author migrated two small RSS reader apps and a space app to Kotlin Multiplatform for iOS compatibility. Since iOS lacked the necessary Android and Java classes, the author preserved the old implementations in test sources, creating a "test oracle" for comparing the new and old code. The test fed the same XML to both parsers and checked if the results matched across six fields such as title, link, date, cover image, summary, and cleaned HTML.
The author identified issues like HTML entities being decoded twice and dates being parsed differently. To ensure the space app's daily card remained consistent, the author wrote a class replicating the java.util.Random algorithm for shuffling, keeping the sequence unchanged. The parity test covers specific inputs but does not guarantee correctness for future or unseen inputs.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.