https://kotlinlang.org logo
#compose
Title
# compose
t

Tudor Luca

05/21/2021, 12:33 PM
I’m looking for a way to generate "test data as source code" based on real server http responses. Basically I want to serialise objects from memory as source code. eg: I have a
data class MyObject(val value: Int)
and 10 objects in memory I want to generate a
data.kt
file like :
Copy code
val obj1 = MyObject(value = 1)
val obj2 = MyObject(value = 12)
val obj3 = MyObject(value = 3)
etc
Context: Jetpack Compose Previews cannot access the file system, so you'd need test data as Kotlin source code, you cannot use a JSON file and parse it, as you would do in a normal junit test. This would be useful as a JVM CLI companion tool when you want complex test data based on a server response that would be tedious to type by hand. Thread in Slack Conversation