Skip to content

mockito:mockBuilder generator fail using MockSpec custom superclass #729

Open
@oznecniV97

Description

@oznecniV97

Mockito generator fail using a custom superclass that extends MockSpec inside GenerateNiceMocks annotation.

Command: dart run build_runner build
Error:

[SEVERE] mockito:mockBuilder on test/mockito_super_test.dart:
Null check operator used on a null value

The problem is related to _mockTargetFromMockSpec method inside lib/src/builder.dart file, because of superclass contains values inside (super) field.

E.g.:

import 'package:flutter_test/flutter_test.dart';
import 'package:mockito/annotations.dart';
import 'package:mockito/mockito.dart';
import 'mockito_super_test.mocks.dart';

class ExampleMockSpec<T> extends MockSpec<T> {
  const ExampleMockSpec() : super();
}

class ExampleService {
  String testMethod() {
    return "example";
  }
}

@GenerateNiceMocks([ExampleMockSpec<ExampleService>()])
void main() {
  test('exampleTest', () {
    const mockValue = "mockValue";
    final mock = MockExampleService();
    when(mock.testMethod()).thenReturn(mockValue);
    expect(mock.testMethod(), mockValue);
  });
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions