To set the context, This I am trying to do in Flutter.
For example,
I have a test that passes, "if I set my mock to say 'no network connection' and expect 'NetworkUnavailable' to result."
Then, I thought to write next test that "if network is available, result could be anything except 'NetworkUnavailable'"
I am struggling to setup an expect matcher for that. Does Mockito has something for this? like AnyExcept([matcher])
Thanks.
CodePudding user response:
There is an isNot
Matcher
that you can combine with other Matcher
s. So, for example, you should be able to do something like: expect(valueToTest, isNot(unwantedValue));
or expect(valueToTest, isNot(isIn([unwantedValue1, unwantedValue2])));
If that doesn't do quite what you want, you also can use the predicate
to easily create your own Matcher
from a boolean function.
(You might not have found these if you were searching the Mockito documentation
because they're part of package:matcher
(normally included as part of package:test
); they're used for unit tests in general, not just for mocks.)