When writing unit tests where you need to pass a common
object with only slight variations it easily becomes tedious to either instantiate a similar object several times or writing a general enough function to return the
object that you want.

With Kotlin you can easily copy data objects and pass in the field you want to change using named parameters.


class MyTest {
  val person = Person(
    name = "Daniel",
    age = 33,
    gender = Gender.MALE 
  )

  @Test
  fun doTest() {
    val put = person.copy(name = "Slartibartfast")
    assertEquals("Slartibartfast", put.name)
  }
}