How is it possible to test this class?

data class BreakdownEntry(val category: Category, val childList: List<BreakdownEntry>, val amount: Double, val currencyCode: String, var percent: String = "") 

If, for example, it was used as Serializable then I would take the given class as a basis and put some data for variables on it, and then check if the data that I recorded is correct.

here, when I try to create an object, I need to go along with all these parameters to the object at once, brr.

    1 answer 1

    Well, you can check that the fields of the objects do not match, each time creating with different parameters:

     @Test @Throws(Exception::class) fun testModelClass() { val category1 = Category().setGuid("category1").save() val category2 = Category().setGuid("category2").save() val breakdownEntry1 = BreakdownEntry(category1, emptyList(), 0.0, "", "") val breakdownEntry2 = BreakdownEntry(category2, emptyList(), 0.0, "", "") assertFalse(breakdownEntry1 == breakdownEntry2) assertFalse(breakdownEntry1.hashCode() == breakdownEntry2.hashCode()) } 

    Also, if you wish, you can simply set some parameter to the percent parameter, then compare it with the initial object.