Anton Afanasev
02/15/2022, 4:48 PMclass Example (val dependency : Dependency, val anotherDependency: AnotherDependency ){
fun doWork() {
dependency.doSomething()
anotherDependency.doSomethingElse()
}
}
class Dependency() {
fun doSomething() {
println("do something")
}
}
class AnotherDependency() {
fun doSomethingElse() {
println("do something")
}
}
Test Class:
class ExampleTest {
private val mockDependency = mockk<Dependency>(relaxed = true)
private val mockAnotherDependency = mockk<AnotherDependency>(relaxed = true)
val subject = Example(mockDependency, mockAnotherDependency)
@Test
fun `when doWork called`() {
subject.doWork()
verifyOrder {
mockDependency.doSomething()
}
}
}
My tests are passing even though I never verified that mockAnotherDependency.doSomethingElse()
invocation. I wonder if there any way to tell mockk to enforce that if any mock object participating in test-case was not verified the test case fails.
Without that check I can seamlessly remove:
anotherDependency.doSomethingElse()
from my actual Example.doWork() and tests will still pass.Mattia Tommasone
02/15/2022, 9:39 PMAnton Afanasev
02/16/2022, 3:13 PMMattia Tommasone
02/16/2022, 3:15 PM