In 1.12.3 `verify { mock.method( withArg {}) }` fails if second call matches. Works in 1.12.2
See original GitHub issuePrerequisites
- I am running the latest version
- I checked the documentation and found no answer
- I checked to make sure that this issue has not already been filed
Expected Behavior
When calling verification using withArg{}
, if there are multiple calls to mock method, and one of calls matches withArg
, the verification should pass.
Current Behavior
If there are multiple calls to method verification will fail. It passed in 1.12.2
Context
Please provide any relevant information about your setup. This is important in case the issue is not reproducible except for under certain conditions.
- MockK version: 1.12.3
- OS: Win/Linux
- Kotlin version: 1.6.10
- JDK version: 17-azul
- JUnit version: 5.8.2
- Unit Test
Minimal reproducible code (the gist of this issue)
@Test
fun `mockk can assert one of calls`() {
open class Mocked {
fun called(i: Int) {}
}
val mock = mockk<Mocked>()
every { mock.called(any()) } just Runs
mock.called(1)
mock.called(3)
verify {
mock.called(withArg { assert(it == 3) })
}
}
I would guess this is caused by https://github.com/mockk/mockk/pull/776, as https://github.com/mockk/mockk/pull/394 fixed https://github.com/mockk/mockk/issues/389 that seemed similar, and https://github.com/mockk/mockk/pull/776 reverted changes.
If this is intentional change, please provide intended way of asserting with many calls.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:7
Top Results From Across the Web
Mockito. Verify method arguments - java - Stack Overflow
So mockito expects your verifier silently returns true for one of the argument set, and false (no assert exceptions) for other valid calls....
Read more >Assertions with an argument | MockK Guidebook
Run assertions with an argument #. There are some special argument matchers that can only be used when verifying that a mocked function...
Read more >mockk-io/Lobby - Gitter
I'm stubbing, or trying to stub, a call to a mock which one of its parameters is a ... import io.mockk.mockk import io.mockk.verify...
Read more >Mockito ArgumentMatchers - Baeldung
We can't use argument matchers outside of verification or stubbing. As per the second point, Mockito will detect the misplaced argument and ...
Read more >How to verify in order method invocation while capturing ...
B, and when I call a method of class A I want to verify that certain ... liberty of rewriting the tests for...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
As a side note, most of the code that I have seen doing
Can also be written as
Which is, IMHO, pretty concise for a few properties to be checked.
In case someone needs to verify more than a few properties, I’d probably still go for a slot.
Yes, I think using predicate is better practice and that is where I will go with rework of my tests.
I will close the issue now.