Comments (6)
cc/ @JeromeA
from mockito.
Not sure, but could be the same bug as #45
from mockito.
So the invalid assumption here is that when you ask for a capture you will do a verify in the test. The first test does not do a verify, and so the capture state isn't reset.
Let me see if we can reset the capture state on the captureAny call. I'll also look into throwing an error if you don't do a verify when you asked for a capture, but I think that would be harder and maybe less developer friendly. There are competing ideas that mocks should error more and not be so lenient.
I'm not sure if we want to have the teardown function. Most of the time you shouldn't need it.
from mockito.
So actually the real core issue is mockito captures are extremely non-picky / broken: they just confuse captures between mock instances, even on different classes, even with methods of different names.
Repro:
import 'package:mockito/mockito.dart';
import 'package:test/test.dart';
class Foo1 {
foo1(x) {}
}
class Foo2 {
foo2(x) {}
}
class MockFoo1 extends Mock implements Foo1 {}
class MockFoo2 extends Mock implements Foo2 {}
main() {
MockFoo1 foo1;
MockFoo2 foo2;
setUp(() {
foo1 = new MockFoo1();
foo2 = new MockFoo2();
when(foo1.foo1(captureAny)).thenAnswer((i) => null);
when(foo2.foo2(captureAny)).thenAnswer((i) => null);
});
test('wrong target', () {
foo1.foo1(1);
foo2.foo2(2);
expect(verify(foo1.foo1(any)).captured, [1]); // Fails: actually gets [1, 2]
expect(verify(foo2.foo2(any)).captured, [2]); // Fails: actually gets []
});
}
from mockito.
Haha ahh! That is super broken. I think resetMockitoState
is actually going to be public. It has real use cases. So that can go into your teardown.
However the other issue you raise about captures is super bad.
from mockito.
The above comment is correct. resetMockitoState
is exported by package:mockito/mockito.dart
, and in fact, it is used in each of Mockito's own tests' tearDown
.
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.