I have this class that I need to test. I am thinking it is because I am creating a new instance of the class A:
class A {
fun getName() = "Name"
}
class B {
private a = A()
fun amend(){
return "${a.getName()}-BName"
}
}
Now I want to test class B in BTest.kt
@Test
fun amendTest(){
val b = B()
val cls = mockk<A>()
//everytime getName is called return empty string
every { cls.getName() } returns ""
//call ammend method
val newName = b.amend()
//make sure the getName is called now
verify { cls.getName()}
Truth.assertThat(newName).isEqualTo("-BName")
}
Basically I want to alter the output of A.getName method to return empty string during tests.