Hello there Do you write unit test data for class...
# android
m
Hello there Do you write unit test data for classes with @SerializedName keys, guarding the annotation values from changing? for example @SerializedName("title"), I'd add a unit test that that value would be always "title", is there any value from doing that?
nono 5
l
Getting it as json and asserting on the json object, maybe?
https://kotest.io/docs/assertions/json/json-overview.html Kotest has some matchers for Json if you want to check it out
❤️ 1
Specifically
m
Not the data class, but the serializer for assert the JSON vs the Kotlin data class values
👍 1
g
Not clear how/why to actually do this. Validate class against json schema is a really nice flow, but if you don't have json schema, if not, your data class is your source of truth, it's not really clear what would you test against, only check with actual Json
m
🤔 i could say to test that using reflection and getting the annotated field for the unit testing.. @gildor can you generate the JSON schema vía internet? If so, that's a clue for thinking about the serialized name assertions
g
I mean you can of course inspect annotation, what I'm saying, that it looks absolutely pointless waste of time to verify annotation content What you instead want to check that your class can encode/decode specific JSON correctly, and checking annotation is very strange way to do this