Comments (6)
I'd say that's a bug.
from mockito.
Ack, unfortunately, verify(...).called(0);
would require a breaking change
When you call verify
or verifyNever
, we don't require any further methods to be called on the resulting object (a _VerifyCall). This is common with verifyNever(...);
, but not very common with verify(...);
, which basically (as you have learned the hard way), expects that at least one invocation has been logged. Users may depend on this behavior today.
In further detail: let's say you call verify(something).called(0);
. While executing the verify(...)
bit, we wish we could see that in the future, called()
will be called, but we can't see the future. Also, when verify
sees that no invocations have been logged, it calls package:test
's fail
method, which immediately throws. There's no way to reach that called()
call, without changing the current behavior.
Now, I'm all for changing the behavior đ , as I don't think many people rely on verify(...);
, but I'll discuss with a few folks on the versioning, etc. In the mean time, I'll clean up the messaging, as you suggest.
from mockito.
@jonahwilliams how about the following breaking change for Mockito 3:
- Calling
verify(a);
does not verify anything about the call count ofa
. - Calling
verify(a);
followed, at some point, by a call towhen
orverifyX
throws an error, stating that a previousverify
call was made without a subsequent call tocalled()
. (But ifverify(a);
is the last statement in a test, it just silently does nothing; I don't think the test framework provides us with any APIs to register hooks at the end of a test. [1]) - The argument to
called
can become optional, so thatverify(a).called()
just sort of, verifies thata
was called more than 0 times. This provides the same functionality as the oldverify(a);
(which was never documented), but I think is easier to read for maintainability; someone unfamiliar would not be expected to guess whatverify(a);
does, but could make an educated guess at whatverify(a).called();
does.
[1] The single downside to this change that I can see is that verify(a);
becomes just a silent no-op, which might be surprising. We could be more heavy-handed and register a expectAsync0
when verify
is called, and then call the expected callback in called()
, but this seems heavy handed...
from mockito.
If verify(a)
does nothing by itself, why not combine it with the expectation? You could arrange the naming so that it corresponds with the current state. For example,
verify(a, called: 1)
or verify.called(a)
/verify.never(a)
That said, I think the proposed changes are perfectly good. We don't throw an error if a user writes a test case without an expect
, so I wouldn't expect verify
to have it's own error prevention here.
from mockito.
@srawlins Is this going to happen for Mockito 3? If not, do you either want to:
- Milestone it for Mockito 4
- Close the issue as not planned
from mockito.
I found a case where verify(someMethod)
is called without .called(n)
:
var verification = verify(someMethod);
expect(verification.captured[0], equals('hey'));
expect(verification.captured[1], startsWith('hi ho'));
So I don't think we can make the changes I proposed, except I'd like to still make the argument to called()
be optional:
the argument to called can become optional, so that verify(a).called() just sort of, verifies that a was called more than 0 times.
from mockito.
Related Issues (20)
- Generated Imports use Unescaped backslashes HOT 3
- Verify constructor HOT 1
- How to test retrofit services with mockito HOT 6
- Question: dockito in dev_dependies? HOT 1
- Error The included part 'mocks.dart' must have a part-of directive. HOT 1
- `verify` failing test but showing in "All calls" HOT 1
- mockito:mockBuilder generator fail using MockSpec custom superclass HOT 5
- How to mock Dio.interceptors.add? HOT 1
- Support for extension-type/inline-class HOT 3
- Why is build_runner is succeeding with 0 outputs? HOT 3
- Support for real executions on Mocking classes HOT 1
- Bad state: Cannot call `when` within a stub response HOT 7
- Cannot create Mock in Dart 3.x: type 'Null' is not a subtype of type 'IOSink' HOT 1
- 'Null' is not a subtype of type 'Future<bool>' HOT 3
- Mocking a class which is created at runtime HOT 1
- Breaking change or typo? HOT 2
- How are we supposed to use any with non null parameters? HOT 2
- Extension type with generic
- Cannot generate mocks for class with method with parameter with default value with a single quote HOT 6
- Dart 3.4.3: invocation_matcher.dart Error: The class 'DeepCollectionEquality' can't be extended outside of its library because it's a final class. HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
đ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. đđđ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google â¤ī¸ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mockito.