Comments (5)
WDYT @TedSander @matanlurey
from mockito.
Thanks for starting this discussion!
I'd love to see some input from @leafpetersen and @munificent too for long-term-isms.
We need to bump Mockito to be Dart 2-only, so that we can remove the pesky
typed
wrapper, so that everything is justany
,argThat
,captureArg
, etc.
👍
However, the new Mockito API will kind of have to adhere to the
typed
shortcoming of having to name named arguments by name, i.e.fn(argThat(equals(3), number: argThat(equals(7), named: 'number'))
. Boooo. Alas, this is unavoidable until we go to a code-genned Mockito, which is a bigger migration than this, and is not necessary until non-nullable types.
Which leads us to: how do we call
any
andcaptureAny
, which are getters today, and have such marvelous ergonomics, when used with a named argument? 😦 Getters cannot take arguments.
Option A: We split the methods
Null get any => ... Null anyNamed(String named) => ... Null get captureAny => ... Null captureAnyNamed(String named) => ...
This adds confusion because now
named
is a positional arg inanyNamed
andcaptureAnyNamed
, but a named arg inargThat
andcaptureThat
. 😦 (Option A2 can be whereanyNamed
andcaptureAnyNamed
use a named argument fornamed
.)
Yeah, this feels like it "fights" with the type system (though I get that it does today already).
I tried it out on a scratchpad:
main() {
var foo = new MockFoo();
when(foo.eat(any)).thenReturn(true);
}
and
main() {
var foo = new MockFoo();
when(foo.eat(any, andDrink: anyNamed(#andDrink)).thenReturn(false);
}
Overall it doesn't feel much worse that the current API, and greps a little better. I also like the fact that it looks like it supports incremental migration better than Option B.
Option B: we force
any
to no longer be a getter, ever 😦 :
Null any({String named}) => ... Null captureAny({String named}) => ...
This would mean using
fn(any(), any(), any())
everywhere. Worse ergonomics, and really confusing and frustrating for people during migration.
This seems more confusing to me than option A, and is a breaking change. I'm not against it, but I'd vote for option A if I get a vote 👎
Option C: Ugh, we go to codegen now
I don't want to do this. It will be huge migration, make Mockito harder to use where codegenning isn't super easy and streamlined, take longer, ... But it does remove the need to use
named
everywhere.
If/when code-generation is first-class (or at least a "classy" second-class with build_runner V2), I could see requiring code generation for Mockito to be OK. Until then, it seems icky. Though, I wouldn't oppose experimenting with allowing both, for example:
import 'package:mockito/mockito.dart';
part 'example.g.dart';
void main() {
var foo = new MockFoo();
when(foo.doThing()).thenReturn('Hello World');
print(foo.doThing()); // Hello World
// Entirely made-up API, similar to built_value.
var bar = new MockBar((c) => c.doThing().thenReturn('Hello World');
print(bar.doThing()); // Hello World
}
// Old-style Mock.
class MockFoo extends Mock implements Foo {}
// New-style Mock.
class MockBar implements Bar {
factory MockBar(void fn(_$MockBarController c)) = _$MockBar;
}
Is there an 'Option D': Do nothing, keep the current API, while designing an Option C-like replacement with the language team? Not saying this is the best option, but I like more options 🦆
from mockito.
I vote A or A2.
I'd like to hold off on C unless there is someone EXTREMELY motivated to work and own the complete solution. Even then I would be a bit hesitant because I don't think we need another migration, and the benefits are not very large for the end user. Mostly mockito just works with a bit of pain for named arguments which aren't the 80% use case.
from mockito.
Given #85, I guess that choices have been made. I'm eager to see this land.
from mockito.
This has been released in 3.0.0-beta
, in #115.
from mockito.
Related Issues (20)
- 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
- Bad state: Asset URI is missing for abstract class JSObject HOT 2
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.