-
-
Notifications
You must be signed in to change notification settings - Fork 381
Closed
Labels
Description
There's documentation of anyConstructed<>()
and constructedWith<>(...)
at https://mockk.io/#constructor-mocks
If you copy those code snippets and execute them anyConstructed
works fine, but constructedWith
:
- The example does not compile to begin with (fixed here)
- After fixing the error the test just fails
assertEquals(2, MockCls().add(1)) // FAIL: expected 2, actual 1
Apparently the mocking has no effect.
Here's an isolated full example (removed the more advanced lines from the docs):
@Test fun test() {
class MockCls(private val a: Int = 0) {
fun add(b: Int) = a + b
}
mockkConstructor(MockCls::class)
every { constructedWith<MockCls>().add(1) } returns 2
assertEquals(2, MockCls().add(1)) // FAIL: expected 2, actual 1
verify {
constructedWith<MockCls>().add(1)
}
}
VitalyVPinchuk