-
Notifications
You must be signed in to change notification settings - Fork 166
Cannot generate mock of class which mixes in DiagnosticableTreeMixin #400
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
to test this, try to generate mocks for this class
|
#397 A question for code generation was asked here as well, but the answer pointed to manual implementation. |
thinking about this, if we could override the generated class somehow to make this work, or maybe use it as a mixin. what do you guys think? |
@matejthetree This issue's description is a mystery to me. I'm not sure what problem or question you have. I'm not sure what "diagnostics problem" means. In reference to the issues about overriding toString with additional parameters, I have an unrelated proposal to allow one to mix in a mixin: #342. Not sure if it would solve this issue... |
@srawlins thanks for the proposal. It might work by creating the mixin that overrides to String. The issue can be easily reproduced by trying to generate mock for Looking forward to your updates |
Sorry for the delay @matejthetree. I do't know what DiagnosticableTreeMixin is. Is this a class you wrote? I'll need a self-contained minimal reproduction in order to debug. |
It is a flutter debug class that is implemented if you want your widget to have custom debug data in the flutter inspection (dev tools). It is used a lot when writing frameworks, to provide details about the state from the inspector itself. I will make a simple app that you can clone. |
here it is. Write this test with the latest version of mockito. import 'package:flutter/foundation.dart';
import 'package:mockito/annotations.dart';
@GenerateMocks([Test])
void main() {}
class Test with DiagnosticableTreeMixin {} The file created will have this error:
I have to go and create manual mocks for huge classes, and this makes it a bit hard to test :) it would be nice If I could define a mixin that would handle this problematic function that I have in all my business logic. |
Ah yes. Similar to #371, but that is for Fakes. This is for Mocks. |
I suspect this is fixed in 5.0.9, but I'm not certain. I cannot reproduce this at HEAD. |
great. Let me try with latest git release |
This is in fact the fake error. Here is the output I get from latest git mockito. class _FakeDiagnosticsNode extends _i1.Fake implements _i2.DiagnosticsNode {}
/// A class which mocks [Test].
///
/// See the documentation for Mockito's code generation for more information.
class MockTest extends _i1.Mock implements _i3.Test {
MockTest() {
_i1.throwOnMissingStub(this);
}
@override
String toString({_i2.DiagnosticLevel? minLevel = _i2.DiagnosticLevel.info}) =>
super.toString();
@override
String toStringShallow(
{String? joiner = r', ',
_i2.DiagnosticLevel? minLevel = _i2.DiagnosticLevel.debug}) =>
(super.noSuchMethod(
Invocation.method(
#toStringShallow, [], {#joiner: joiner, #minLevel: minLevel}),
returnValue: '') as String);
@override
String toStringDeep(
{String? prefixLineOne = r'',
String? prefixOtherLines,
_i2.DiagnosticLevel? minLevel = _i2.DiagnosticLevel.debug}) =>
(super.noSuchMethod(
Invocation.method(#toStringDeep, [], {
#prefixLineOne: prefixLineOne,
#prefixOtherLines: prefixOtherLines,
#minLevel: minLevel
}),
returnValue: '') as String);
@override
String toStringShort() => (super
.noSuchMethod(Invocation.method(#toStringShort, []), returnValue: '')
as String);
@override
_i2.DiagnosticsNode toDiagnosticsNode(
{String? name, _i2.DiagnosticsTreeStyle? style}) =>
(super.noSuchMethod(
Invocation.method(
#toDiagnosticsNode, [], {#name: name, #style: style}),
returnValue: _FakeDiagnosticsNode()) as _i2.DiagnosticsNode);
@override
List<_i2.DiagnosticsNode> debugDescribeChildren() =>
(super.noSuchMethod(Invocation.method(#debugDescribeChildren, []),
returnValue: <_i2.DiagnosticsNode>[]) as List<_i2.DiagnosticsNode>);
@override
void debugFillProperties(_i2.DiagnosticPropertiesBuilder? properties) =>
super.noSuchMethod(Invocation.method(#debugFillProperties, [properties]),
returnValueForMissingStub: null);
} End the error is indeed on
|
I tried to do it with new API but with no luck @GenerateMocks([
Test
], customMocks: [
MockSpec<Test>(as: #TestCustom, fallbackGenerators: {#toString: toString})
])
String toString(
{TextTreeConfiguration? parentConfiguration,
DiagnosticLevel? minLevel = DiagnosticLevel.info}) {
return '';
} I still get the same |
OK this is a duplicate of #371 then. |
Since the recommended way is to code generate mocks, is there a way to use code generation with the fix mentioned here?
#233
The text was updated successfully, but these errors were encountered: