Hi all. I have a question regarding sequense/order...
# mockk
a
Hi all. I have a question regarding sequense/order verification. Consider following: Subject:
Copy code
class 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:
Copy code
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:
Copy code
anotherDependency.doSomethingElse()
from my actual Example.doWork() and tests will still pass.
m
If i understood your request correctly, there’s an open issue about it: https://github.com/mockk/mockk/issues/334
a
Thank you @Mattia Tommasone this is the behaviour I was looking for. I guess it can be very beneficial to verify mock interaction is strict, as it enforce that no mock invokation is missing. Is it something you have a priority for?
m
not really, but i’d be glad to review a PR about it 🙂
1