You are currently viewing Mockk – allow tested method to change mock value

Mockk – allow tested method to change mock value

i’m trying it with this code that i take in docs but doens’t work. it’s possible?

take a look:

// Tests.kt

@Test
fun test`() { val mock: SkillDTO = mockk()`

every { mock.name } returns "oldValue"
every { mock.name = any() } propertyType String::class answers { fieldValue = value }
val result = skillService.test(mock, "newValue")

assertThat(result).isEqualTo("newValue")
}

// SkillService.kt

fun test(dto: SkillDTO, aa: String): String {
dto.name = aa
return dto.name!!
}

submitted by /u/broken168
[link] [comments]