Comments (8)
Wow, thanks for discovering this! I can confirm this is a proper albeit dirty solution. For some months now I couldn't regenerate my mocks (and had to update the generated classes manually). I saw that part of the mocks are not generated without json_serializable included. It might have to do with the typedef that I use. I will create an example later today too.
from mockito.
Here's a simple sample. Notice the different output when json_serializable is included.
https://github.com/Mark-Toten/mockito_freezed
FWIW: I ran into this issue when trying to update from Mockito 5.2.0 to 5.4.0
from mockito.
We do support a global_options config to affect ordering for a given package (without overriding builder configs), see https://github.com/dart-lang/build/blob/master/docs/faq.md#how-can-i-adjust-builder-ordering
from mockito.
Please create a sample (preferably minimal) project that makes it possible to reproduce the problem. I don't use freezed myself.
from mockito.
This may be an ordering issue? I'm not sure why adding an otherwise unrelated builder should force a different ordering, but it could. If mockito
runs before freezed
it won't see the generated code. I'm a little surprised it doesn't complain about resolution errors if that is the case. Can you check the order of the builders in the generated .dart_tool/build/entrypoint/build.dart
file and report the ordering of mockito
and freezed
between when it works and doesn't work?
I don't think it's sensible to add a required_inputs
here, but it also doesn't seem like a healthy coupling if freezed
needs to add a runs_before
either. @jakemac53 - what is our current best practice for this situation? I wonder if we are missing some way for end users to give a hint about this in their config without doing a full override of the config...
It might also work to split the test directory into a separate target which depends on the library target. As long as the freezed
models are in lib/
, and the mockito
usage is in test/
, the target ordering might resolve the problem. Having to add targets for this is not very discoverable, and feels like a cliff from having a config with implicit targets.
from mockito.
Yes, this is an ordering issue: without json_serializable
mockBuilder
runs before freezed
. json_serializable
helps because freezed
explicitly requests running before json_serializable
https://github.com/rrousselGit/freezed/blob/7e478b841f247b8fb0a95722a88392950df22489/packages/freezed/build.yaml#L25
I don't know though, what makes mockBuilder
run after json_serializable
.
I'll leave to @jakemac53 to comment, what would be possible ways to fix it (except for asking freezed
to add another runs_before clause).
But I have a general question: freezed objects are immutable values with no behavior, why would you even want to mock them?
from mockito.
But I have a general question: freezed objects are immutable values with no behavior, why would you even want to mock them?
This is a good point - mocking a data model is not a good practice.
from mockito.
But I have a general question: freezed objects are immutable values with no behavior, why would you even want to mock them?
In my case the classes used to be regular classes which I migrated to immutable freezed classes. The unittests where written for the original classes and didn't need change after this migration, since Mockito generated fine classes up until Mockito 5.2.0.
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 2
- 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.