Gasan
11/10/2023, 4:15 PMJoffrey
11/10/2023, 4:15 PMJacob
11/10/2023, 4:15 PMGasan
11/10/2023, 4:17 PMJoffrey
11/10/2023, 4:18 PM""
, 0
, false
, null
Gasan
11/10/2023, 4:19 PMnewMyType()
and have the value all initializedJoffrey
11/10/2023, 4:20 PMGasan
11/10/2023, 4:22 PMJoffrey
11/10/2023, 4:22 PMGasan
11/10/2023, 4:23 PMJacob
11/10/2023, 4:28 PMGasan
11/10/2023, 4:29 PMcopy()
method for individual fields from Java?copy()
for all fields is availableJosé González D'Amico
11/10/2023, 4:37 PMGasan
11/10/2023, 4:38 PMJosé González D'Amico
11/10/2023, 4:38 PMWout Werkman
11/10/2023, 4:38 PMGasan
11/10/2023, 4:45 PMWout Werkman
11/10/2023, 4:48 PM.copy
. But based on your second question you already figured that out yourself 🙂.Charles Flynn
11/11/2023, 9:12 AMfun aPerson(
name: String = randomString(),
age: Int = randomInt(1, 100)
eyeColour: EyeColour = randomEnumValue()
) = Person(name, age, eyeColour)
Then in a test that say only cares about being provided an adult but not their name or eye colour you'd just go val adult = aPerson(age = 18)
.
It's a useful technique because in production code it might not be appropriate to set defaults but in tests you do end up in this scenario of only caring about certain fields. It also helps to self document your tests in that regard.
There's a library which I've not used because it seems a bit overkill to me but you might be interested in: https://serpro69.github.io/kotlin-faker/
Do not use mocks for this type of thing.Adam S
11/11/2023, 9:14 AM