https://kotlinlang.org logo
Title
l

Lou Morda

05/22/2019, 6:01 PM
Hi @ianbrandt I'm trying to utilize TDD in a Kotlin spring boot project. I'm using data classes for my POJOs. Is there any reason to unit test a data class? It literally just has a primary constructor and it's data fields. No business logic, no methods.
r

rakeeb

05/22/2019, 10:36 PM
it would make sense to add tests for POJOs only if you have a custom implementation for
equals
or id you are adapting the POJO from some other class
i

ianbrandt

05/23/2019, 12:57 AM
I suppose you could write an equals, hashCode, and toString smoke test to express the intent that it stays a data class? I’ve used https://jqno.nl/equalsverifier/ to do that with minimal code for Java DTOs in the past. I haven’t tried it with Kotlin yet. If you give it a shot and it works well, or doesn’t, I’d love to hear.
l

Lou Morda

05/23/2019, 4:38 PM
Very cool, thanks! These data classes will always remain data classes in this project. However you're right anything can happen, and someone could theoretically change that