https://kotlinlang.org logo
Title
l

Lou Morda

05/23/2019, 4:43 PM
Do data classes need unit tests if we know they only have a primary constructor and no methods? data class(val id: String, val firstName: String, val lastName: String)
r

Ruckus

05/23/2019, 4:44 PM
That depends entirely on your testing strategy.
👍 1
e

elizarov

05/23/2019, 4:47 PM
It is like
assertEquals(4, 2 + 2)
— sometimes it does make sense, but usually it does not.
💯 4
😁 1
l

LeoColman

05/23/2019, 6:00 PM
I would say that data classes are already covered at many places when testing is concerned
If they have any behavior different from only keeping data, (for instance a static parse or whatever), I'd write a test for them
j

Jeremy

05/23/2019, 10:37 PM
Not for unit tests. The behavior of the data class is already tested by JB at language/compiler level. Can be tested as part of integration tests