I've tried to find the difference here https://pub.dev/packages/mockito and using documentation to this matchers but didn't get it. Could someone provide example where I supposed to use captureThat rather than argThat?
Asked
Active
Viewed 1,285 times
1 Answers
1
The documentation for argThat
states:
An argument matcher that matches an argument that matches
matcher
.
The documentation for captureThat
states:
An argument matcher that matches an argument that matches
matcher
, and captures the argument for later access withcaptured
.
Therefore the difference is that captureThat
captures the matched argument for later examination whereas argThat
does not.
See Capturing arguments for further assertions from the Mockito documentation for examples for how to use captured arguments.

jamesdlin
- 81,374
- 13
- 159
- 204
-
well I see, but still didn't get difference. I can do the same with argThat and without expect, right? like this `verify(cat.eatFood(argThat(contains("food"))));` – Ilya Maximencko Nov 24 '20 at 11:28
-
1For that trivial example, sure, you can use `argThat` instead of `captureThat`. For something more complex, you might prefer to check the captured value using some other mechanism than using a `Matcher`. Or maybe you just want to inspect the captured value for debugging. – jamesdlin Nov 24 '20 at 12:59