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
LeoColman
10/21/2024, 4:14 PM
Getting it as json and asserting on the json object, maybe?
Not the data class, but the serializer for assert the JSON vs the Kotlin data class values
👍 1
g
gildor
10/29/2024, 8:46 AM
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
marlonlom
10/29/2024, 9:02 PM
🤔 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
gildor
10/30/2024, 3:15 AM
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